这是我到目前为止所拥有的,鞋子的类型是boots, wellingtons, leather, trainers (in that order)
我想遍历并分配值,所以我有类似
var shoeArray = { boots : '3', wellingtons: '0', leather : '1', trainers: '3'};
目前,我只是可以使用{3,0,1,3}
其中的一个数组,但这并不是很有帮助。
function shoe_types() {
var shoeArray = [];
$('[type=number]').each(function(){
$('span[data-field='+$(this).attr('id')+']').text($(this).val());
shoeArray.push ( parseInt($(this).val()) );
});
return shoeArray;
}
检查此功能
function shoe_types() {
var shoeArray = {}; // note this
$('[type=number]').each(function(){
$('span[data-field='+$(this).attr('id')+']').text($(this).val());
shoeArray[$(this).attr('id')] = parseInt($(this).val()) ;
});
return shoeArray;
}
PS:假设$(this).attr('id')
具有所有鞋子类型
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句