【发布时间】:2014-02-25 17:17:57
【问题描述】:
我已经开发了 jquery json autoxcomplete 搜索,我想在结果到来时终止空格。目前,当我在前面搜索放置空间的东西时,它不会给出任何结果。请告诉我如何添加 thsi 选项工作
jQuery.extend( jQuery.ui.autocomplete.prototype, {
_renderItem: function( ul, item ) {
var term = this.element.val(),
regex = new RegExp( '(' + term + ')', 'gi' );
html = item.label.replace( regex , "<b>$&</b>" );
return jQuery( "<li></li>" )
.data( "item.autocomplete", item )
.append( jQuery("<a></a>").html(html) )
.appendTo( ul );
}
});
jQuery.noConflict();
jQuery(function(){
jQuery("#searchr").autocomplete({
source:'<?php echo JURI::root().'modules/mod_jomdirectory_search/tmpl/religious.php'; ?>',
minLength:1
});
});
【问题讨论】:
-
@Colandus :谢谢,顺便说一句,当有人搜索“temple”时如何修剪中间空格,例如当一个词是“temple”时,自动完成仍然有效。请指教
-
@s_fdo 这应该这样做stackoverflow.com/questions/6623231/…
-
@RossG :谢谢我通过了,可以把它放在这里 html = item.label.replace( regex , "$&" );我的意思是这部分“.replace(/ /g,'')”
标签: jquery json jquery-ui jquery-autocomplete