我已經實現了使用JQuery的自動完成功能,當我選擇數據時,它被存儲在結果表中,選擇後,我需要清除自動完成的文本框,我無法。搜索了相同的並得到了這個Clear text box in Jquery Autocomplete after selection,但我不知道該把它放在哪裏以及在螢火蟲中,我在函數(事件,UI)中出錯。 請幫助...我的代碼如下。自動完成後清除文本框在jquery中選擇
$(function() {
function log(message) {
$("<div>").text(message).prependTo("#log").click(function(o){
$(this).remove();
});
$("#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: 1,
select: function(event, ui) {
log(ui.item ?
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");
}
});
});
它沒有工作.. – madhu
什麼是你得到了錯誤螢火蟲 – Swarne27
它適用於我,但爲什麼?我不知道作爲一個JavaScript新手。 – kxxoling