我試圖實現標記 - 它的輸入,但我想限制用戶只從自動填充框中選擇 值。 我嘗試使用源json來overTenderTagAdded事件,並檢查源代碼中是否存在標記 但沒有運氣。jQuery標記 - 它只允許來自自動完成源的標記
這是代碼,請參閱beforeTagAdded函數。
$(document).ready(function() {
var itemId;
var theTags = $('#msg_to');
theTags.tagit({
autocomplete: {
source: [{ id: "1", value: 'David'}, { id: "2", value: 'John' }],
minLength: 0,
select: function (event, ui) {
itemId = ui.item.id;
theTags.tagit("createTag", ui.item.value);
}
},
showAutocompleteOnFocus: true,
afterTagAdded: function (event, ui) {
if (itemId) {
$(ui.tag).find('input').attr('name', "tag[\'" + itemId + "']['" + ui.tagLabel + "']");
itemId = null;
}
},
beforeTagAdded: function (event, ui) {
var id = ui.autocomplete.source; // not working
// what to do next?
}
})
});
</script>
在此先感謝
謝謝所有,我發現使用select2更容易使用。 –