欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET jQuery 實(shí)例18 通過使用jQuery validation插件校驗DropDownList

 更新時間:2012年02月03日 17:31:34   作者:  
這節(jié)我們還可以通過直接設(shè)置DropDownList屬性來設(shè)置jQuery validation插件的校驗規(guī)則和提示信息
先看界面代碼:
復(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,腳本代碼改為如下,也可以實(shí)現(xiàn)同樣的效果:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
$(function () {
$("#form1").validate({
rules: { dllCar: "required" },
messages: { dllCar: "至少選擇一種車!" },
errorLabelContainer: $("#message")
});
});
</script>

相關(guān)文章

最新評論