ASP.NET jQuery 實(shí)例18 通過(guò)使用jQuery validation插件校驗(yàn)DropDownList
更新時(shí)間:2012年02月03日 17:31:34 作者:
這節(jié)我們還可以通過(guò)直接設(shè)置DropDownList屬性來(lái)設(shè)置jQuery validation插件的校驗(yàn)規(guī)則和提示信息
先看界面代碼:
<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:DropDownList ID="dllCar" runat="server" ToolTip="至少選擇一種車!" CssClass="required">
<asp:ListItem Value="" Text="---請(qǐng)選擇---"></asp:ListItem>
<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:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="提交" />
</td>
</tr>
</table>
</fieldset>
<div id="message" class="alertmsg">
</div>
</div>
</form>
DropDownList控件屬性ToolTip會(huì)轉(zhuǎn)換為Title,title的值可以作為校驗(yàn)規(guī)則required的提示信息,屬性CssClass的值required就指定了插件的校驗(yàn)規(guī)則。
腳本代碼:
<head id="Head1" runat="server">
<title>Recipe18</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({
errorLabelContainer: $("#message")
});
});
</script>
<style type="text/css">
.alertmsg
{
color: #FF0000;
}
</style>
</head>
顯示效果:
另外如果不設(shè)置DropDownList的屬性ToolTip和CssClass,腳本代碼改為如下,也可以實(shí)現(xiàn)同樣的效果:
<script type="text/javascript">
$(function () {
$("#form1").validate({
rules: { dllCar: "required" },
messages: { dllCar: "至少選擇一種車!" },
errorLabelContainer: $("#message")
});
});
</script>
復(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:DropDownList ID="dllCar" runat="server" ToolTip="至少選擇一種車!" CssClass="required">
<asp:ListItem Value="" Text="---請(qǐng)選擇---"></asp:ListItem>
<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:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="提交" />
</td>
</tr>
</table>
</fieldset>
<div id="message" class="alertmsg">
</div>
</div>
</form>
DropDownList控件屬性ToolTip會(huì)轉(zhuǎn)換為Title,title的值可以作為校驗(yàn)規(guī)則required的提示信息,屬性CssClass的值required就指定了插件的校驗(yàn)規(guī)則。
腳本代碼:
復(fù)制代碼 代碼如下:
<head id="Head1" runat="server">
<title>Recipe18</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({
errorLabelContainer: $("#message")
});
});
</script>
<style type="text/css">
.alertmsg
{
color: #FF0000;
}
</style>
</head>
顯示效果:
另外如果不設(shè)置DropDownList的屬性ToolTip和CssClass,腳本代碼改為如下,也可以實(shí)現(xiàn)同樣的效果:
復(fù)制代碼 代碼如下:
<script type="text/javascript">
$(function () {
$("#form1").validate({
rules: { dllCar: "required" },
messages: { dllCar: "至少選擇一種車!" },
errorLabelContainer: $("#message")
});
});
</script>
您可能感興趣的文章:
- jQuery插件Validation快速完成表單驗(yàn)證的方式
- jQuery Validation PlugIn的使用方法詳解
- jquery插件validation實(shí)現(xiàn)驗(yàn)證身份證號(hào)等
- jQuery驗(yàn)證插件validation使用指南
- jquery validation驗(yàn)證身份證號(hào),護(hù)照,電話號(hào)碼,email(實(shí)例代碼)
- ASP.NET中實(shí)現(xiàn)jQuery Validation-Engine的Ajax驗(yàn)證
- ASP.NET中實(shí)現(xiàn)jQuery Validation-Engine的Ajax驗(yàn)證實(shí)現(xiàn)代碼
- 修改jQuery Validation里默認(rèn)的驗(yàn)證方法
- ASP.NET jQuery 實(shí)例11 通過(guò)使用jQuery validation插件簡(jiǎn)單實(shí)現(xiàn)用戶登錄頁(yè)面驗(yàn)證功能
- jQuery Validation實(shí)例代碼 讓驗(yàn)證變得如此容易
- 詳解jQuery的表單驗(yàn)證插件--Validation
相關(guān)文章
JQuery實(shí)現(xiàn)倒計(jì)時(shí)按鈕具體方法
頁(yè)面中需要實(shí)現(xiàn)某個(gè)按鈕點(diǎn)擊完后,禁用它,并顯示倒計(jì)時(shí)。這個(gè)默認(rèn)是3秒,代碼如下2013-11-11js根據(jù)json數(shù)據(jù)中的某一個(gè)屬性來(lái)給數(shù)據(jù)分組的方法
今天小編就為大家分享一篇js根據(jù)json數(shù)據(jù)中的某一個(gè)屬性來(lái)給數(shù)據(jù)分組的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-10-10jQuery插件ajaxfileupload.js實(shí)現(xiàn)上傳文件
這篇文章主要為大家詳細(xì)介紹了jQuery插件ajaxfileupload.js實(shí)現(xiàn)上傳文件的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05淺談jQuery的bind和unbind事件(綁定和解綁事件)
下面小編就為大家?guī)?lái)一篇淺談jQuery的bind和unbind事件(綁定和解綁事件)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03JQuery表格拖動(dòng)調(diào)整列寬效果(自己動(dòng)手寫(xiě)的)
當(dāng)鼠標(biāo)停留在表頭邊框線上時(shí),鼠標(biāo)會(huì)變成表示左右拖動(dòng)的形狀,接著拖動(dòng)鼠標(biāo),會(huì)在表格中出現(xiàn)一條隨鼠標(biāo)移動(dòng)的豎線,最后放開(kāi)鼠標(biāo),表格列寬會(huì)被調(diào)整2014-09-09