我在我的脚本中使用jQuery
tag-it:
$("#user_autocomplete").tagit({ tagSource: function (request,response) { $.ajax({ data: { term: request.term },type: "POST",url: "/site2/message/users.PHP",dataType: "json",success: function (data) { response($.map(data,function (item) { return { label: item,value: item } })); } }); },tagLimit: 3,autocomplete: { delay: 0,minLength: 1 },});
在这种情况下,确认所有输入字段.但是我只想要添加可用的字段.怎么做?
解决方法
发表于OP:
我使用beforeTagAdded函数我找到了我的答案:
tagSource: function(request,response) { $.ajax({ data: { term:request.term },url: "/site2/message/users.PHP",dataType: "json",success: function( data ) { array = data; response( $.map( data,function( item ) { return { label:item,value: item } })); } }); },tagLimit :3,autocomplete: {delay: 0,minLength: 1},beforeTagAdded: function(event,ui) { if(array.indexOf(ui.tagLabel) == -1) { return false; } if(ui.tagLabel == "not found") { return false; } },