如何在struts 2中使用带有多个tagit的jquery自动完成

我在struts2中使用jQuery中的自动完成的多个标记示例。但它没有用。我不使用struts自动完成标记。

    $(function(){ $('#tags input').on('focusout',function(){ var txt= this.value.replace(/[^a-zA-Z0-9\+\-\.\#]/g,'');//allowed characters if(txt) { $(this).before(''+txt.toLowerCase()+''); } this.value=""; }).on('keyup',function(e){ // if: comma,enter(delimit more keyCodes with | pipe) if(/(188|13)/.test(e.which))$(this).focusout(); }); $('#tags').on('click','.tag',function(){ if(confirm("Really delete this tag?"))$(this).remove(); }); });   jQuery(function(){ $("#mytag").autocomplete("list.jsp"); });   //htlm input text tag------ 

这是Tag-it和autocomplete的一个工作示例。 看看它,看看它是如何工作的,一定要采用最新的库并根据您的需求进行定制:

运行演示

HTML

 

JS

 $("#mytags").tagit({ autocomplete: { source: function( request, response ) { $.ajax({ url: "http://ws.geonames.org/searchJSON?username=foobar", dataType: "jsonp", data: { featureClass: "P", style: "full", maxRows: 12, name_startsWith: request.term }, success: function( data ) { response( $.map( data.geonames, function( item ) { return { label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName, value: item.name } })); } }); }, minLength: 2 } });