ASP.NET jQuery 實(shí)例17 通過使用jQuery validation插件校驗(yàn)ListBox
更新時(shí)間:2012年02月03日 17:27:44 作者:
這節(jié)介紹jQuery validation插件一個(gè)新的校驗(yàn)規(guī)則屬性rangelength,通過數(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#入門教程之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中each循環(huán)的跳出和結(jié)束實(shí)例
下面小編就為大家?guī)硪黄猨Query中each循環(huán)的跳出和結(jié)束實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
jQuery實(shí)現(xiàn)checkbox即點(diǎn)即改批量刪除及中間遇到的坑
這篇文章主要介紹了jQuery實(shí)現(xiàn)checkbox即點(diǎn)即改批量刪除及中間遇到的坑,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-11-11
jQuery實(shí)現(xiàn)基本淡入淡出效果的方法詳解
這篇文章主要介紹了jQuery實(shí)現(xiàn)基本淡入淡出效果的方法,結(jié)合實(shí)例形式詳細(xì)分析了jQuery使用fadeIn()、fadeOut()及fadeToggle()等方法控制頁(yè)面元素淡入淡出顯示效果的相關(guān)操作技巧,需要的朋友可以參考下2018-09-09
合并table相同單元格的jquery插件分享(很精簡(jiǎn))
正好項(xiàng)目中有個(gè)小需求, 要求把表格指定列中內(nèi)容相同的單元格進(jìn)行合并,本質(zhì)上涉及的就是td的rowspan屬性, 數(shù)出含相同內(nèi)容單元格的個(gè)數(shù), 然后給第一個(gè)與上一行內(nèi)容不同的td其rowspan屬性附上正確的值即可, 為了能直觀的理解2011-06-06
jQuery中bind,live,delegate與one方法的用法及區(qū)別解析
本篇文章主要是對(duì)jQuery中bind,live,delegate與one方法的用法及區(qū)別進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-12-12
jQuery實(shí)現(xiàn)非常實(shí)用漂亮的select下拉菜單選擇效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)非常實(shí)用漂亮的select下拉菜單選擇效果,通過jQuery模擬select下拉選擇效果,并具有點(diǎn)擊選中下拉項(xiàng)進(jìn)入輸入框的功能,非常美觀實(shí)用,需要的朋友可以參考下2015-11-11
jQuery 添加樣式屬性的優(yōu)先級(jí)別方法(推薦)
下面小編就為大家?guī)硪黄猨Query 添加樣式屬性的優(yōu)先級(jí)別方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06

