0
我試圖使用jqueryui自動完成添加元素 但我無法刪除附加元素 我該怎麼辦?使用jQuery和jQueryui自動完成刪除附加元素
$(function() {
var products = [
{ "sn":"P00101","label":"Product 1"},
{ "sn":"P00102","label":"Product 2"},
{ "sn":"P00103","label":"Product 3"},
{ "sn":"P00104","label":"Product 4"}
]
$("#project").autocomplete({
minLength: 0,
source: products,
focus: function(event, ui) {
$("#project").val(ui.item.label);
return false;
},
select: function(event, ui) {
$("#project").val(ui.item.label);
$("#project-id").val(ui.item.sn);
$("<li>").html("["+ui.item.sn+"] "+ui.item.label+"<input type=text size=5><a href='#' class='remove'>Remove</a>").appendTo("#result");
return false;
}
})
.data("ui-autocomplete")._renderItem = function(ul, item) {
return $("<li>")
.append("<a>[" + item.sn + "] " + item.label + "</a>")
.appendTo(ul);
};
$(".remove").live("click",function() {
$(this).parent("li").remove();
});
});
,在這裏我的HTML源
<input id="project">
<input type="hidden" id="project-id">
<h3>Result</h3> <ol id="result" class='lists'></ol>