我的 HTML 代码如下所示:
<div id="single"><br><br>
1) effew<br>
<input name="answer0" id="answer0" value="1" type="radio"> ewf
<input name="answer0" id="answer0" value="2" type="radio"> avb
</div>
<div id="single"><br><br>
2) fe<br>
<input name="answer1" id="answer1" value="1" type="radio"> few
<input name="answer1" id="answer1" value="2" type="radio"> eww
<input name="answer1" id="answer1" value="3" type="radio"> tfs
</div>
我想以 id 为单个迭代上述 div 标签,然后在每个 div 标签中以单个 id 获取选定单选按钮的值。编写的jQuery代码是:
$("input[name=single]").each( function() {
var val = $('input[name=answer]:checked').val();
alert(val);
});
上面的 jQuery 代码似乎不起作用。请。建议我该如何解决?