I have multiple email inputs:
<input type="text" class="email" value="{{email}}">
And I want to retrieve each email input and put them all in one list:
var names = $(".email").val();
But right now I only get the first value instead of the full list. What's wrong?
您可以使用$.map
创建值的数组。
var names = $.map($(".email"), function(e) {return e.value});
jQuery.each function will help you,
var email array = [];
jQuery(".email").each(function{
email_array[email_array.length] = jQuery(this).val();
#you can any operation in this block
});
now, you have all email in email_array
I'm guessing you're looking for a string list?
Try the "each" function!
var names = "";
$(".email").each(function(){
if(names != ""){
names += ", ";
}
names += $(this).val();
});
console.log(names);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.