0
我想實現標籤功能就像在stackoverflow網站,也是刪除標籤的功能。我如何實現自動提示功能以及刪除按鈕?
我指的是jquery ui自動完成插件。
對於刪除功能,我指的是以下網站:website link
我需要的是,標籤應該用逗號分隔的功能,應該對無標籤的限制,用戶可以選擇&應該有還可以移除標籤。
我知道在select函數中有規定來限制no。的建議。
我試圖合併所提到的網站上給出的功能。
爲此我修改了選擇功能。
select: function(event, ui) {
var terms = split(this.value);
if (terms.length <= 2) {
// 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("");
var friend = ui.item.value,
span = $("<span>").text(friend),
a = $("<a>").addClass("remove").attr({
href: "javascript:",
title: "Remove " + friend
}).text("x").appendTo(span);
//add friend to friend div
span.insertBefore("#txtTopic");
} else {
terms.pop();
}
this.value = terms.join(",");
return false;
}
現在我得到以下結果:
如何實現此功能是有限制的多個標籤,逗號分隔和刪除功能?