首先,我创建了一个包含n行的表,每行都包含两个单选按钮。我需要从选中的表行和选项中获取所有id。我的意思是,如果用户选择是或否。
<table border='1' style='width:100%'>
<tr>
<th>Date</th>
<th>Time</th>
<th>Confirm Order?</th>
</tr>
<tr id='56'>
<td>".$date." </td>
<td>".time." </td>
<td>".$prog." </td>
<td>
<input type='radio' name='prog1' />NO
<input type='radio' name='prog1' />SI</td>
</tr>
</table>到目前为止,我得到的是检查行中的I。如下所示:
var idss = [];
$(':radio:checked').each(function(index) {
var closestTr = $(this).closest('tr').attr('id');
idss.push($(this).closest('tr').attr('id'));
});
$(function test() {
$.ajax({
type: 'POST',
url: 'test.php',
data: {
idss: idss
}
});如何获得一个包含所有ids的数组(其中选择了'no‘),以及一个包含所有ids (其中选择了'yes’)的数组。
发布于 2015-05-14 08:45:47
我在这里做了个小手脚:https://jsfiddle.net/7w2df640/
这是js:
function getArray(){
ar = {};
$(".datarow").each(function(i,o){
ar[$(o).attr("id")] = $(o).find("input[type='radio']:checked").val()
});
console.log(ar);
}对于html,您必须在行中添加一个类:
<tr class="datarow" id='56'>并向广播中添加一个值:
<input type='radio' name='prog1' checked value="no" />最后,您将得到一个与您想要的完全相同的数组:
Object {56: "si", 57: "no"}这有意义吗?
https://stackoverflow.com/questions/30227081
复制相似问题