Javascript 发送具有相同ID的多个复选框的值
我有一张表格里面的桌子。它有两列,第一列是复选框,第二列是输入 其结构如下:Javascript 发送具有相同ID的多个复选框的值,javascript,jquery,ajax,forms,checkbox,Javascript,Jquery,Ajax,Forms,Checkbox,我有一张表格里面的桌子。它有两列,第一列是复选框,第二列是输入 其结构如下: <table> <tr> <td> <input type="checkbox" name="choose" id="choose" class="choose"> </td> <td> <input type="text" name="item" id="item" class="item" > </td> </tr
<table>
<tr>
<td>
<input type="checkbox" name="choose" id="choose" class="choose">
</td>
<td>
<input type="text" name="item" id="item" class="item" >
</td>
</tr>
</table>
现在我需要对复选框做同样的操作,但我不知道如何继续
谁能帮我一下吗
非常感谢 您可以尝试以下方法:
var arrayItem= [];
$(".choose:checked").each(function(index, elem){
//you could store them like a key-valuepair so you no where the value belongs to.
//you can take the ID of the elem parm inside the for each and store it with the control id.
arrayItem.push(elem.val());
})
params += '&items='+ arrayItem;
相同的代码应该与复选框一起使用。您只需要记住,只发送选中的项目。i、 e.
$(“.choose:checked”)
我同意@Imdad,而且不要忘记在页面中放置多个具有相同ID的控件(这是一个错误)。附带问题:为什么要为数据设置“&items=”?POST请求不需要像URL那样编码。
var arrayItem= [];
$(".choose:checked").each(function(index, elem){
//you could store them like a key-valuepair so you no where the value belongs to.
//you can take the ID of the elem parm inside the for each and store it with the control id.
arrayItem.push(elem.val());
})
params += '&items='+ arrayItem;