开发者

How to get values of jQuery Tags Input plugin

开发者 https://www.devze.com 2023-01-23 15:12 出处:网络
I use this jQuery Tags Input plugin: jQuery Tags Input but I can\'t get the values on my ph开发者_高级运维p file.If you are trying to get the individual values using jQuery you can use:

I use this jQuery Tags Input plugin:

jQuery Tags Input

but I can't get the values on my ph开发者_高级运维p file.


If you are trying to get the individual values using jQuery you can use: (This is assuming the text input you made into a tag input has an id of "keywords")

$('#keywords').tagsInput({  
    'height':'auto',  
    'width':'350px',
    'defaultText':'',
    'delimiter': '|'
});
/*The delimiter option above overrides the default comma delimiter in the plugin allowing commas in tags if you prefer that...*/

var $keywords = $("#keywords").siblings(".tagsinput").children(".tag");  
var tags = [];  
for (var i = $keywords.length; i--;) {  
    tags.push($($keywords[i]).text().substring(0, $($keywords[i]).text().length -  1).trim());  
}  

/*Then if you only want the unique tags entered:*/  
var uniqueTags = $.unique(tags);  
alert(uniqueTags.toSource());


To get the list of emails from:

<input type="text" name="to_addresses" class="to_addresses" data-role="tagsinput" >

I use:

$emails = []
$.map($(".tagsinput span span"),function(e,i){
$emails.push($(e).text().trim());
})

Works for me, thought I'd share it.


 $("#btn").click(function () {
         var $tagWord = $("#tags_2").siblings(".tagsinput").children(".tag");
         var tags = [];
         for (var i = $tagWord.length; i--; ) {
             tags.push($($tagWord[i]).text().substring(0, $($tagWord[i]).text().length - 1).trim());
         }

         /*Then if you only want the unique tags entered:*/
         var uqTags = $.unique(tags);
         alert(uqTags.toSource());

     });


using jquery you can do it in one line:

$.map($('.tag span'),function(e,i){return $(e).text().trim();})


$("input").tagsinput('items')   

["Amsterdam","Washington","Sydney","Beijing","Cairo"]

$("input").val()    

"Amsterdam,Washington,Sydney,Beijing,Cairo"


can you provide an example of what is POSTed? you can do so by pointing your form to go to api.fatherstorm.com?query and copying the json data that it gives you


it change the hidden input value, and will post the data when you click submit , you can test it by a simple php script. print_r($_POST) to see it.


Based on sagivo answer you can write a function like this :

function getKeywords() {
  return $.map($('.tag span'),function(e,i){
    return $(e).text().trim();
  });
}

That will return an array of keywords present in the input. Like this [ "there", "it", "is" ]

0

精彩评论

暂无评论...
验证码 换一张
取 消