我试图从元框中保存WordPress数据库中的一些数据.
我有一个下拉列表来选择一些选项,我想通过元框保存所选的数据库选项.
但是我在PHP中的保存功能有些困难:
<?php
function add_admin_menu_class_meta_box() {
$pages = array('post', 'portfolio');
foreach( $pages as $page ) {
add_meta_box('custom_element_grid_class','Element grid size', 'custom_element_grid_class_meta_box', $page, 'side', 'high');
}
}
add_action( 'admin_menu', 'add_admin_menu_class_meta_box' );
function custom_element_grid_class_meta_box(){
?>
<label>Choose the size of the element : </label>
<select name="custom_element_grid_class" id="custom_element_grid_class">
<option value="normal" <?php selected( $meta_element_class, 'normal' ); ?>>normal</option>
<option value="square" <?php selected( $meta_element_class, 'square' ); ?>>square</option>
<option value="wide" <?php selected( $meta_element_class, 'wide' ); ?>>wide</option>
<option value="tall" <?php selected( $meta_element_class, 'tall' ); ?>>tall</option>
</select>
<?php
}
add_action('save_post', …Run Code Online (Sandbox Code Playgroud) 我使用jquery自动完成来搜索xml文件.
自动完成功能正常工作.但是,当我单击自动完成菜单结果的元素项时,输入搜索框内的值不可见.因为在输入框中添加了很多空格(制表符).
我真的不明白它来自哪里(这个空白区域).
我做了一个小提琴,但是在这个小提琴上,值正确地放在输入框内......它们不是这个空白区域:http://jsfiddle.net/8zJkS/5/
脚本:
$("input#search").autocomplete({
minLength: 3,
source: myArr,
response: function(event, ui) {
if (ui.content.length === 0) {
$("#noMatches").show();
} else {
$("#noMatches").hide();
}
},
focus: function (event, ui) {
$('input#search').focus();
return false;
},
select: function (event, ui) {
$("input#search").val(ui.item.value);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我也用键盘搜索悬停效果的方式.我也有一些文字出现在我搜索时,我不知道如何删除它.
似乎jquery自动完成文档非常差.
抱歉我的英语,我是法国人.
我有一个脚本,允许替换不需要的HTML标签和转义引号来"提高"安全性,并主要防止脚本标记和onload注入等....这个脚本用于"纹理化"从中检索的内容innerHTML.
但是,它在我的执行时间附近乘以3(在循环中).我想知道是否有更好的方法或更好的正则表达式:
function safe_content( text ) {
text = text.replace( /<script[^>]*>.*?<\/script>/gi, '' );
text = text.replace( /(<p[^>]*>|<\/p>)/g, '' );
text = text.replace( /'/g, '’' ).replace( /'/g, '’' ).replace( /[\u2019]/g, '’' );
text = text.replace( /"/g, '”' ).replace( /"/g, '”' ).replace( /"/g, '”' ).replace( /[\u201D]/g, '”' );
text = text.replace( /([\w]+)=&#[\d]+;(.+?)&#[\d]+;/g, '$1="$2"' );
return text.trim();
};
Run Code Online (Sandbox Code Playgroud)
编辑:这里有一个小提琴:https://fiddle.jshell.net/srnoe3s4/1/.小提琴script显然不喜欢javascript字符串中的标签所以我没有添加它.
我的脚本中有几个 if 语句需要很多条件,我想以更有效的方式编写它们,并使用“速记符号”来提高可读性。
例如,我有这个 if 语句:
if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {
/*** some code ***/
}
Run Code Online (Sandbox Code Playgroud)
所以我用 indexOf 和 array 写了它,但我不确定这是否是最好的方法:
if (['abc', 'def', 'ghi' ,'jkl'].indexOf(x) > -1) {
/*** some code ***/
}
Run Code Online (Sandbox Code Playgroud)
我几乎可以肯定还有其他一些更清洁、更快捷的方法......
我正在使用此正则表达式从网址获取Vimeo视频ID:
/\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|video\/|)(\d+)(?:[a-zA-Z0-9_\-]+)?/i
Run Code Online (Sandbox Code Playgroud)
但是,这个正则表达式似乎有一些拼写错误和问题,当我尝试使用它时,由于JSLint,例如:
Expected a regexp factor and instead saw ')'.
Run Code Online (Sandbox Code Playgroud)
我无法找到问题的确切位置.
javascript ×3
regex ×2
autocomplete ×1
conditional ×1
focus ×1
html-select ×1
if-statement ×1
input ×1
jquery ×1
meta-boxes ×1
php ×1
replace ×1
sanitization ×1
select ×1
vimeo ×1
wordpress ×1