我在页面中有4个动态添加的radiobuttonlist。我要检查一下 其中一个选项在jquery中检查了其中4个。怎么做到呢?我尝试在c#中的每个radiobuttonlist中添加相同的类(" rb1")并尝试使用以下代码,但无法获得所需的结果。
$('table.rb1 input:radio').each(function () {
var checked = $(this).find('input:radio:checked');
if (checked.length == 0) {
alert("All questions are mandatory !!! ")
result = false;
return;
}
});
Html代码如下:
<table id="ctl00_ContentPlaceHolder1_ctl34" class="rb1" border="0">
<tr>
<td>
<input id="ctl00_ContentPlaceHolder1_ctl34_0" type="radio" name="ctl00$ContentPlaceHolder1$ctl34" value="1" />
<label for="ctl00_ContentPlaceHolder1_ctl34_0">excellent</label>
</td>
<td>
<input id="ctl00_ContentPlaceHolder1_ctl34_1" type="radio" name="ctl00$ContentPlaceHolder1$ctl34" value="2" />
<label for="ctl00_ContentPlaceHolder1_ctl34_1">good</label>
</td>
<td>
<input id="ctl00_ContentPlaceHolder1_ctl34_2" type="radio" name="ctl00$ContentPlaceHolder1$ctl34" value="3" />
<label for="ctl00_ContentPlaceHolder1_ctl34_2">average</label>
</td>
<td>
<input id="ctl00_ContentPlaceHolder1_ctl34_3" type="radio" name="ctl00$ContentPlaceHolder1$ctl34" value="4" />
<label for="ctl00_ContentPlaceHolder1_ctl34_3">not relevant</label>
</td>
</tr>
</table>
答案 0 :(得分:0)
您只需检查每个length
table.rb1 input[type="radio"]:checked
的{{1}}是否等于0
:
table
$('#check').on('click',function(){
$('table.rb1').each(function(){
if($('input[type="radio"]:checked',this).length == 0) alert('None checked');
});
});
$('#reset').on('click',function(){
$('table.rb1 input[type="radio"]').prop('checked',false);
});