【发布时间】:2015-09-25 19:45:50
【问题描述】:
我有一个带有单选按钮列表的两个文本框。如果两个测试为空白,则应提醒“文本框为空白”,如果不为空白,则应提醒“日期已启用”。
这是我用 javascript 尝试过的
function checked() {
var radio = document.getElementById('<%=rbtn1.ClientId%>');
var cal1 = document.getElementById('<%=textstqo.ClientId%>').value;
var cal2 = document.getElementById('<%=textedqo.ClientId%>').value;
if (radio.checked = true) {
if(cal1 == '' && cal2 =='')
{
alert("dates cannot be blank");
return false
}else
{
alert("dates are enabled");
return true
}
}
}
单选按钮列表
<asp:RadioButtonList ID="rbtn1" runat="server" RepeatDirection="Vertical" RepeatLayout="Table" Height="300px" Width="101px" onClick="checked()" >
<asp:ListItem Text="one" Value="one" Enabled="true"></asp:ListItem>
<asp:ListItem Text="two" Value="two" Enabled="true" ></asp:ListItem>
<asp:ListItem Text="three" Value="three" Enabled="true"></asp:ListItem>
已编辑 错误:预期功能
第一个警报正在工作。当我尝试在其他部分检查警报时,它显示上述错误 我只向您展示了第一个单选按钮“quaterone”,而 javascript 也适用于 quaterone
谁能告诉我我做错了什么。提前谢谢
【问题讨论】:
-
您是否尝试过,如果选中任何一个单选按钮,则验证文本框,否则将其保留?
-
no.. 仅当单击第一个单选按钮“quaterone”@
-
@shanish:no.. 仅当单击第一个单选按钮“quaterone”时
-
//
when i tried to check the alert in else part it shows the above error I have only shown you the first radio button that is "quaterone" and the javascript is also for quaterone.// 你到底在哪里得到错误。是否来自您问题中给出的来源? -
@shanish:问题是我只希望在单选按钮列表中的第一个单选按钮(quaterone)被选中时发出警报。但是当我点击另一个单选按钮时它也会显示警报
标签: javascript radiobuttonlist