ASP.NET jQuery 實(shí)例16 通過控件CustomValidator驗(yàn)證RadioButtonList
更新時間:2012年02月03日 17:26:01 作者:
上一節(jié)已經(jīng)介紹過控件CustomValidator的使用方法,下面直接看代碼
界面代碼:
<form id="form1" runat="server">
<div align="center">
<fieldset style="width: 350px; height: 200px;">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
<td>
請選擇汽車類型:
</td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="rbCar" runat="server">
<asp:ListItem Value="1" Text="奔馳汽車"></asp:ListItem>
<asp:ListItem Value="2" Text="寶馬汽車"></asp:ListItem>
<asp:ListItem Value="3" Text="奧迪汽車"></asp:ListItem>
<asp:ListItem Value="4" Text="現(xiàn)代汽車"></asp:ListItem>
<asp:ListItem Value="5" Text="豐田汽車"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="提交" />
</td>
</tr>
</table>
</fieldset>
<asp:CustomValidator ID="ctvCar" runat="server" Display="Dynamic" ErrorMessage="至少選擇一種車!"
ForeColor="Red" ClientValidationFunction="rbCar_Validation"></asp:CustomValidator>
</div>
</form>
腳本代碼:
<head id="Head1" runat="server">
<title>Recipe16</title>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
function rbCar_Validation(sender, args) {
args.IsValid = ($("#rbCar :radio:checked").length > 0);
}
</script>
</head>
顯示效果:
復(fù)制代碼 代碼如下:
<form id="form1" runat="server">
<div align="center">
<fieldset style="width: 350px; height: 200px;">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
<td>
請選擇汽車類型:
</td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="rbCar" runat="server">
<asp:ListItem Value="1" Text="奔馳汽車"></asp:ListItem>
<asp:ListItem Value="2" Text="寶馬汽車"></asp:ListItem>
<asp:ListItem Value="3" Text="奧迪汽車"></asp:ListItem>
<asp:ListItem Value="4" Text="現(xiàn)代汽車"></asp:ListItem>
<asp:ListItem Value="5" Text="豐田汽車"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="提交" />
</td>
</tr>
</table>
</fieldset>
<asp:CustomValidator ID="ctvCar" runat="server" Display="Dynamic" ErrorMessage="至少選擇一種車!"
ForeColor="Red" ClientValidationFunction="rbCar_Validation"></asp:CustomValidator>
</div>
</form>
腳本代碼:
復(fù)制代碼 代碼如下:
<head id="Head1" runat="server">
<title>Recipe16</title>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
function rbCar_Validation(sender, args) {
args.IsValid = ($("#rbCar :radio:checked").length > 0);
}
</script>
</head>
顯示效果:

您可能感興趣的文章:
- jQuery Validate 驗(yàn)證,校驗(yàn)規(guī)則寫在控件中的具體實(shí)例
- ASP.NET jQuery 實(shí)例15 通過控件CustomValidator驗(yàn)證CheckBoxList
- 使用jQuery.Validate進(jìn)行客戶端驗(yàn)證(初級篇) 不使用微軟驗(yàn)證控件的理由
- 基于jquery實(shí)現(xiàn)的服務(wù)器驗(yàn)證控件的啟用和禁用代碼
- 教你用AngularJS框架一行JS代碼實(shí)現(xiàn)控件驗(yàn)證效果
- js控制.net驗(yàn)證控件是否可用。
- 驗(yàn)證控件與Button的OnClientClick事件詳細(xì)解析
- fileupload控件 文件類型客戶端驗(yàn)證實(shí)現(xiàn)代碼
- asp.net MaxLengthValidator 最大長度驗(yàn)證控件代碼
- jQuery密碼強(qiáng)度驗(yàn)證控件使用詳解
相關(guān)文章
JQuery事件e參數(shù)的方法preventDefault()取消默認(rèn)行為
JQuery事件的e參數(shù)的方法preventDefault()可以取消對象的默認(rèn)行為,下有個不錯的示例,大家可以參考下,希望對大家有所幫助2013-09-09
JQueryEasyUI框架下的combobox的取值和綁定的方法
這篇文章主要介紹了JQueryEasyUI框架下的combobox的取值和綁定的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-01-01
利用浮層使select不可選的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄酶邮箂elect不可選的實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,祝大家游戲愉快哦2016-12-12
基于jquery css3實(shí)現(xiàn)點(diǎn)擊動畫彈出表單源碼特效
這篇文章主要介紹了基于jquery css3實(shí)現(xiàn)點(diǎn)擊動畫彈出表單,彈出的表單沒有任何遮蓋層,在web前端程序開發(fā)中經(jīng)常會用到,需要的朋友可以參考下2015-08-08

