1
asp.net這是我的Default.aspx頁面的Javascript與單選按鈕列表
<td>Radio </td>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" >
<asp:ListItem Text = "One" Value = "1"></asp:ListItem>
<asp:ListItem Text = "Two" Value = "2"></asp:ListItem>
<asp:ListItem Text = "Three" Value = "3"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td><div id="Div1" style="color:Red;display:none"></div></td>
</tr>
<tr>
<td>Dropdown </td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" >
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<center>
<asp:Button ID="Button1" runat="server" Text="Edit"/>
<asp:Button ID="Button2" runat="server" Text="DropDown" OnClientClick="return ValidateDropDown('DropDownList1');" />
<asp:Button ID="Button3" runat="server" Text="RadioValidate" OnClientClick = "return ValRad(document.getElementById('RadioButtonList1'));" />
</center>
這是我分離的JavaScript文件:
function ValRad(CntrlID) {
alert("Radio");
var RB1 = CntrlID;
alert("1");
var radio = RB1.getElementsByTagName("input");
alert("2");
var isChecked = false;
alert("3");
for (var i = 0; i < radio.length; i++) {
if (radio[i].checked) {
isChecked = true;
break;
}
}
if (!isChecked) {
alert("Please select an item");
}
return isChecked;
}
我無法驗證單選按鈕列表以及下拉列表,請幫助我... (SORRY格式不正確,我是新成員)請幫助我
RequiredFieldValidator的是服務器端控制, 我使用javascript – mmj89
是其口味的問題想在客戶端;)@ user3166530 –
請儘快幫助我。謝謝 它沒有asp服務器端控件。 – mmj89