我正在尝试一个由 RadioButtonList 组成的简单验证rblstPallet
。我尝试了以下代码:
javascript
var rblstPallet = document.getElementById('rblstPallet');
var counter = 0;
for (var intCount = 0; intCount < rblstPallet.length; intCount++) {
if (rblstPallet[intCount].checked) { //this step is not working
console.log(intCount); //I checked using this step
counter++;
}
}
if (counter == 0) {
//MSG: please select any item
}
else {
// Redirect to next page function
}
.aspx
<asp:RadioButtonList ID="rblstPallet" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Wood</asp:ListItem>
<asp:ListItem>Plastic</asp:ListItem>
<asp:ListItem>None</asp:ListItem>
</asp:RadioButtonList>
问题是,如果我什至选择了一个单选按钮,那么该counter
值也保持不变。当我调试代码时,我知道那行
if (rblstPallet[intCount].checked) {
甚至没有执行,甚至没有在控制台中显示任何错误。我正在通过这个链接。我试过这个链接(不工作)。
请帮忙。