![](/img/trans.png)
[英]Remove autocomplete selected item from the list in asp.net and Ajax
[英]how to remove selected item from the list after performing autocomplete?
我已經使用Jquery
實現了自動完成事件,並且工作正常,現在我需要在我選擇的列表中實現刪除或刪除功能。 請參見下面的代碼。
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#poolName" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "/DataWeb/getPoolName",
type : 'post',
dataType: 'json',
data: { name_startsWith: request.term },
success: function( data ) {
console.log(data);
response( $.map( data, function( item ) {
return {
label: item.poolName,
value: item.poolName
}
}));
}
});
},
minLength: 2,
select: function( event, ui ) {
log( ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
});
例如:如果在文本框中鍵入“ a”,我將獲得以“ a”開頭的名稱列表,並選擇5個以“ a”開頭的名稱。 它將存儲在“日志” ID中。 池名稱:
<div style="margin-top: 2em; font-family: serif; font-size: medium;"> Result:
<div> <fieldset id="log" style="height: 200px; width: 300px; overflow: auto;"> </fieldset> </div>
</div>
</div>
</form>
現在,如果要刪除所選名稱之一,我該如何實施? 有人可以幫忙嗎?
提前致謝
將您的log
功能更改為:
注意:這會在每條消息前面添加一個“刪除”按鈕,單擊該按鈕將刪除該消息。
function log( message ) {
var _m = '<div style="float:left;">' + message + '</div>';
_m += '<div style="float:right;"><input type="submit" value="Remove"></div>';
_m += '<div style="clear:both;"></div>';
$( "<div>" ).html( _m ).prependTo( "#log" ).click(function(o){
$(this).remove();
});
$( "#log" ).scrollTop( 0 );
}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.