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