我有一个单选按钮列表
<asp:RadioButtonList CssClass="radioLable" ID="rbListPointsCat" runat="server" RepeatDirection="Horizontal"
AutoPostBack="true" OnSelectedIndexChanged="rbListPointsCat_SelectedIndexChanged">
<asp:ListItem runat="server" Value="Yes" />
<asp:ListItem runat="server" Value="No" />
</asp:RadioButtonList>
我正在使用以下JS函数
function CheckValue(sender, args) {
var rblist = document.getElementById('<% =rbListPointsCat.ClientID%>');
for (var x = 0; x < rblist.cells.length; x++) {
if (rblist.cells[x].checked) {
var Choice = (rblist.cells[x].innerText);
alert(Choice);
}
}
if (Choice=="No") {
if (txtRemarks.value == "") {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
else {
args.IsValid = true;
}
}
但无法获得已检查的值。这将是未定义的。 请告诉我哪里出错了?
答案 0 :(得分:0)
按名称呼叫
function CheckValue(sender, args) {
var rblist = document.getElementByName('<% =rbListPointsCat.ClientID%>');
for (var x = 0; x < rblist.cells.length; x++) {
if (rblist.cells[x].checked) {
var Choice = (rblist.cells[x].innerText);
alert(Choice);
}
}
if (Choice=="No") {
if (txtRemarks.value == "") {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
else {
args.IsValid = true;
}
}