如何获取文本框组的值,并使用jquery将它们放入(key:Value)数组中


How to get Values of Group of textbox and put them in a ( key : Value ) array with jquery?

如何使用JQuery获取文本框组的值并将其放入(key : value)数组中?

foreach ($students as $value) {
    ?>
    <tr>
        <td>
            <input name="result[]" class="result" id="<?= $value['stuId'];?>" type="text" required=""/>
        </td>
    </tr>
    <?php
        }
    ?>

我不知道如何获取一组输入值的值。

在这种情况下,哪种技术是有用的?我如何使数组的键成为输入id?

演示:http://jsfiddle.net/uyko2ahx/

根据您的需要,您可以使用简单的数组或对象,其中键:值对:

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);