如何获取文本框组的值,并使用(key : value)
将其放入JQuery数组中?
foreach ($students as $value) {
?>
<tr>
<td>
<input name="result[]" class="result" id="<?= $value['stuId'];?>" type="text" required=""/>
</td>
</tr>
<?php
}
?>
我不知道如何获得一组输入值的值。
在这种情况下,哪种技术是有用的?如何使数组的键是输入id?
发布于 2015-04-06 14:20:51
演示:http://jsfiddle.net/uyko2ahx/
根据您的需要,您可以使用简单的数组或对象,并使用key:value对:
arr=[];
$( ".result" ).each(function( index ) {
key=$( this ).prop('id');
value=$(this).val();
arr.push(key+':'+value);
});
console.log(arr);
obj={};
$( ".result" ).each(function( index ) {
key=$( this ).prop('id');
value=$(this).val();
obj[key]=value;
});
console.log(obj);
https://stackoverflow.com/questions/29480130
复制相似问题