質問

I am using multiple tag-it example with autocomplete in jQuery in struts2.But its not worked.I am not use struts autocomplete tag.

<script src="js/jquery.autocomplete.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
 $('#tags input').on('focusout',function(){ 
var txt= this.value.replace(/[^a-zA-Z0-9\+\-\.\#]/g,'');//allowed characters
if(txt) {
$(this).before('<span class="tag">'+txt.toLowerCase()+'</span>');
}
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();
 });
});
</script>
<script type="text/javascript">
jQuery(function(){
$("#mytag").autocomplete("list.jsp");
});
</script>
<!-- tsk -->
//htlm input text tag------
 <div id="tags">
<input type="text" value="" placeholder="Add a tag" id="mytag" />
 </div>
役に立ちましたか?

解決

This is a working example with Tag-it and autocomplete. Check it out, look how it works, be sure to take the latest libraries and customize it to your needs:

Running demo

HTML

<ul id="mytags" >

</ul>

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 }
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top