ASP.NET jQuery 實(shí)例17 通過(guò)使用jQuery validation插件校驗(yàn)ListBox
更新時(shí)間:2012年02月03日 17:27:44 作者:
這節(jié)介紹jQuery validation插件一個(gè)新的校驗(yàn)規(guī)則屬性rangelength,通過(guò)數(shù)組方式賦值
這里我們舉例校驗(yàn)ListBox兩個(gè)規(guī)則:
•校驗(yàn)必選項(xiàng)
•選擇范圍在0~4項(xiàng)
界面代碼:
<form id="form1" runat="server">
<div align="center">
<fieldset style="width: 350px; height: 200px;">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
<td>
請(qǐng)選擇汽車類型:
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="lstCar" runat="server" Rows="5" SelectionMode="Multiple">
<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:ListBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="提交" />
</td>
</tr>
</table>
</fieldset>
<div id="message" class="alertmsg">
</div>
</div>
</form>
腳本代碼:
<head id="Head1" runat="server">
<title>Recipe17</title>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript" src="Scripts/jquery.validate.js"></script>
<script type="text/javascript">
$(function () {
$("#form1").validate({
rules: {
lstCar: { required: true, rangelength: [0, 4] }
},
messages: {
lstCar: { required: "至少選擇一種車!",
rangelength: "選擇的范圍為零到四種車!"
}
},
errorLabelContainer: $("#message")
});
});
</script>
<style type="text/css">
.alertmsg
{
color: #FF0000;
}
</style>
</head>
界面效果:
•校驗(yàn)必選項(xiàng)
•選擇范圍在0~4項(xiàng)
界面代碼:
復(fù)制代碼 代碼如下:
<form id="form1" runat="server">
<div align="center">
<fieldset style="width: 350px; height: 200px;">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
<td>
請(qǐng)選擇汽車類型:
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="lstCar" runat="server" Rows="5" SelectionMode="Multiple">
<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:ListBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="提交" />
</td>
</tr>
</table>
</fieldset>
<div id="message" class="alertmsg">
</div>
</div>
</form>
腳本代碼:
復(fù)制代碼 代碼如下:
<head id="Head1" runat="server">
<title>Recipe17</title>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript" src="Scripts/jquery.validate.js"></script>
<script type="text/javascript">
$(function () {
$("#form1").validate({
rules: {
lstCar: { required: true, rangelength: [0, 4] }
},
messages: {
lstCar: { required: "至少選擇一種車!",
rangelength: "選擇的范圍為零到四種車!"
}
},
errorLabelContainer: $("#message")
});
});
</script>
<style type="text/css">
.alertmsg
{
color: #FF0000;
}
</style>
</head>
界面效果:
您可能感興趣的文章:
- C#入門(mén)教程之ListBox控件使用方法
- asp.net中ListBox 綁定多個(gè)選項(xiàng)為選中及刪除實(shí)現(xiàn)方法
- 對(duì)ListBox的添加移除操作實(shí)例分享
- 給ListBox添加雙擊事件示例代碼
- ListBox實(shí)現(xiàn)上移,下移,左移,右移的簡(jiǎn)單實(shí)例
- asp.net listbox實(shí)現(xiàn)單選全選取消
- .net中實(shí)現(xiàn)listBox左右移動(dòng)
- C#保存listbox中數(shù)據(jù)到文本文件的方法
- C#讀取文本文件到listbox組件的方法
- C#實(shí)現(xiàn)讓ListBox適應(yīng)最大Item寬度的方法
- ASP.NET中DropDownList和ListBox實(shí)現(xiàn)兩級(jí)聯(lián)動(dòng)功能
- ASP.NET中 ListBox列表框控件的使用方法
相關(guān)文章
jQuery插件DataTables分頁(yè)開(kāi)發(fā)心得體會(huì)
這篇文章主要為大家分享了jQuery插件DataTables分頁(yè)開(kāi)發(fā)心得體會(huì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08jQuery實(shí)現(xiàn)當(dāng)前頁(yè)面標(biāo)簽高亮顯示的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)當(dāng)前頁(yè)面標(biāo)簽高亮顯示的方法,涉及jQuery通過(guò)自定義函數(shù)操作css樣式的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03jQuery.Validate 使用筆記(jQuery Validation范例 )
學(xué)習(xí)jQuery Validation,于是手寫(xiě)一公共范例,并收藏以便后用,里面附有測(cè)試代碼,需要的朋友一起來(lái)測(cè)試。2010-06-06jQuery簡(jiǎn)單判斷值是否存在于數(shù)組中的方法示例
這篇文章主要介紹了jQuery簡(jiǎn)單判斷值是否存在于數(shù)組中的方法,涉及jQuery數(shù)組遍歷及基于$.inArray的元素判斷相關(guān)操作技巧,需要的朋友可以參考下2018-04-04ASP.NET MVC中EasyUI的datagrid跨域調(diào)用實(shí)現(xiàn)代碼
因?yàn)閑asyUI使用的是JQuery的異步方法加載數(shù)據(jù),應(yīng)該遵循JQuery的跨域訪問(wèn)規(guī)則2012-03-03jquery改變disabled的boolean狀態(tài)的三種方法
改變disabled的boolean狀態(tài),下面為大家介紹三種比較不錯(cuò)的方法,大家可以參考下2013-12-12jQuery實(shí)現(xiàn)無(wú)限往下滾動(dòng)效果代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn)無(wú)限往下滾動(dòng)效果代碼,涉及jQuery基于ajax交互操作數(shù)據(jù)庫(kù)數(shù)據(jù)及頁(yè)面元素動(dòng)態(tài)變換的相關(guān)技巧,需要的朋友可以參考下2016-04-04