2014-02-25 28 views
0

我已經開發jquery json autoxcomplete搜索那裏我想結束空間時結果來臨。目前,當我搜索somthing放置太空infront它不會給任何結果。請諮詢我如何添加thsi選項工作如何在jquery自動填充上跳過空格?

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 
       }); 
      }); 
+2

的http://計算器。 com/questions/498970/how-do-i-trim-a-string-in-javascript – Colandus

+0

@Colandus:謝謝,btw如何修正中間空格,如果某人搜索「tem ple」sti l自動完成工作。請諮詢 – fdz

+0

@s_fdo這應該做到這一點http://stackoverflow.com/questions/6623231/remove-all-white-spaces-from-text – RossG

回答

0

在 '微調' 功能看看...

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

http://jsfiddle.net/3s75T/

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

:謝謝,順便說一句,這是可能使搜索以及逃生空間,如果單詞是「abc efg」,如果人類輸入「abcefg」也自動完成填充結果?請諮詢 – fdz

+0

是的,http://stackoverflow.com/questions/14236873/disable-spaces-in-input-and-allow-back-arrow – superUntitled

+0

如果這有助於你,請標記爲已回答。 – superUntitled