Javascript 将具有相同类名的表单输入字段放入数组中
所以我有一些类似的字段:Javascript 将具有相同类名的表单输入字段放入数组中,javascript,jquery,Javascript,Jquery,所以我有一些类似的字段: [1] [2] [3] with attributes: name=item1,item2,item3 and class = item 我要做的是将所有三个字段放入一个数组: 因此: 有没有一种方法可以使用unique class属性:item来实现这一点?获取项目并循环它们。将每一个添加到您的列表中 var items = []; $('.item').each(function(index, value){ //where value is an input
[1] [2] [3] with attributes: name=item1,item2,item3 and class = item
我要做的是将所有三个字段放入一个数组:
因此:
有没有一种方法可以使用unique class属性:item来实现这一点?获取项目并循环它们。将每一个添加到您的列表中
var items = [];
$('.item').each(function(index, value){
//where value is an input
items.push(value);
});
获取项目并循环浏览它们。将每一个添加到您的列表中
var items = [];
$('.item').each(function(index, value){
//where value is an input
items.push(value);
});
可以使用Array.map方法从属性中返回数组:
var items=$'.item'.attr'name'.split',',//转换为数组
arr=[].map.callitems,函数值{//use
return+value.match/\d/[0];//从数组项返回数字值
};
$'pre'.htmlJSON.stringifyarr;
item
可以使用Array.map方法从属性中返回数组: var items=$'.item'.attr'name'.split',',//转换为数组 arr=[].map.callitems,函数值{//use return+value.match/\d/[0];//从数组项返回数字值 }; $'pre'.htmlJSON.stringifyarr;item
尝试此$.items.toArray可获得相同的结果,可能是有效的结果。尝试此$.items.toArray可获得相同的结果,可能是有效的结果