【问题标题】:How to escape spaces on jquery autocomplete?如何在 jquery 自动完成上转义空格?
【发布时间】: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


【解决方案1】:

看看'trim'函数...

https://api.jquery.com/jQuery.trim/

http://jsfiddle.net/3s75T/

$('input').on('blur', function() {
  term = $.trim($(this).val());
  alert( term ); 
});

【讨论】:

  • :谢谢,顺便说一句,如果单词是“abc efg”,如果人们将其键入为“abcefg”,是否也可以在搜索时创建转义空格?请指教
猜你喜欢
  • 2015-06-03
  • 2012-01-26
  • 2019-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多