jQuery的自动完成,并在Word preSS特殊字符 [英] jQuery Autocomplete and Special Characters in WordPress
本文介绍了jQuery的自动完成,并在Word preSS特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
希望林不遗漏一个已经存在的这个问题的答案。进出口与使用jQuery UI的自动完成功能提供种类选择在前端形成一个字preSS主题工作。 code如下。问题是,如果一个类名有一个与功放,则其不能显示字符,而是显示&放大器;放大器;
在自动完成框。我一定能正确显示的字符?
`
的jQuery(函数(){ / *自动完成* /
VAR availableTags = [
< PHP
$ terms_array =阵列();
$术语= get_terms('专业','hide_empty = 0'); 如果($计算)的foreach($条款$项){
$ terms_array [] =''$ term-方式>名'。';
}
回声破灭('',$ terms_array);
?>
];
函数split(VAL){
返回val.split(/ \\ S * /);
}
功能extractLast(项){
返回拆分(项).pop();
}
jQuery的(#majors_wrap输入)。生活(的keydown,函数(事件){
如果((event.key code === jQuery.ui.key code.TAB || event.key code === jQuery.ui.key code.COMMA)及&安培;
jQuery的(本)。数据(自动完成).menu.active){
。事件preventDefault();
}
})。自动完成({
的minLength:0,
来源:函数(请求,响应){
//后向委托自动完成,但提取的最后一届
响应(jQuery.ui.autocomplete.filter(
availableTags,extractLast(request.term)));
},
重点:函数(){
。jQuery的('input.ui-自动完成输入')VAL('');
// prevent值插入焦点
返回false;
},
选择:函数(事件,UI){ VAR而言=拆分(THIS.VALUE);
//删除当前输入
terms.pop();
//添加所选项目
terms.push(ui.item.value);
//添加占位符来获得在最后逗号和空格
terms.push();
//this.value = terms.join(,);
THIS.VALUE = terms.join(); jQuery的(本).blur();
jQuery的(本)。重点(); 返回false;
}
}); });
< / SCRIPT>`
解决方案
只需更换它返回的数据: terms.push(ui.item.value.replace(&放大器;放大器;, &安培;);
Hopefully im not missing an already existing answer to this question. Im working with a wordpress theme that uses jquery ui autocomplete to provide category selections in a front end form. Code is below. Problem is that if a category name has an &, it cant display the character and instead shows &
in the autocomplete box. Can i make it show the character properly?
`
jQuery(function(){
/* Auto Complete */
var availableTags = [
<?php
$terms_array = array();
$terms = get_terms( 'majors', 'hide_empty=0' );
if ($terms) foreach ($terms as $term) {
$terms_array[] = '"'.$term->name.'"';
}
echo implode(',', $terms_array);
?>
];
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
jQuery("#majors_wrap input").live( "keydown", function( event ) {
if ( (event.keyCode === jQuery.ui.keyCode.TAB || event.keyCode === jQuery.ui.keyCode.COMMA) &&
jQuery( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
}).autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( jQuery.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
focus: function() {
jQuery('input.ui-autocomplete-input').val('');
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
//this.value = terms.join( ", " );
this.value = terms.join( "" );
jQuery(this).blur();
jQuery(this).focus();
return false;
}
});
});
</script>`
解决方案
Just replace it in the returned data: terms.push( ui.item.value.replace("&","&" );
这篇关于jQuery的自动完成,并在Word preSS特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文