[英]jQuery - UI autocomplete issue
我的功能看起來像這樣
mailto_input.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB && $( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
}).autocomplete({
source: function( request, response ) {
$.getJSON( "core/search.php", {
term: extractLast( request.term )
}, response );
},
search: function(){
// custom minLength
var term = extractLast( this.value );
if ( term.length < 2 ) {
return false;
}
},
focus: function() {
// 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( "; " );
return false;
}
});
我想要實現的是,限制用戶僅選擇服務器端數據。 我的意思是,僅當PHP方面有任何結果時,我才想將term添加到輸入框中。 否則,通知用戶此服務器中沒有數據
對於前。
我想防止添加諸如sdsf
類的sdsf
(在這種情況下,服務器的響應類似於[]
)。 換句話說,僅在服務器端至少有1條建議時才添加。 否則,保持不變,並通知用戶有關問題。
那可能嗎? 我怎樣才能達到這個結果?
去Tokeninput看看吧 。 它確實可以滿足您的要求。
另外,這里的演示只是為了確保它是您想要的...
好吧,他們這樣做的方式是將標簽交換為跨度。
<div id="taginput">
<span id="tags">
<span>tagname</span>
</span>
<input type="text" id="tagtext"/>
</div>
您必須做到這一點,以便在跨度之前添加建議:
$('.suggestion_element_class').click(function() {
textof = this.text();
$('#tags').append('<span>' + textof + '</span>');
$('#tagtext').val('');
});
當然,您必須首先獲得建議以及所有建議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.