asp.net jquery instance 18 verifies dropdownlist_jquery by using the jquery validation plug-in

Source: Internet
Author: User
First look at the interface code:
Copy Code code as follows:

<form id= "Form1" runat= "Server" >
<div align= "center" >
<fieldset style= "width:350px; height:200px; " >
<table border= "0" cellpadding= "3" cellspacing= "3" >
<tr>
<td>
Please choose the type of car:
</td>
</tr>
<tr>
<td>
<asp:dropdownlist id= "Dllcar" runat= "Server" tooltip= "choose at least one car!" "cssclass=" Required ">
<asp:listitem value= "" text= "---Please select---" ></asp:ListItem>
<asp:listitem value= "1" text= "Mercedes Benz Car" ></asp:ListItem>
<asp:listitem value= "2" text= "BMW Car" ></asp:ListItem>
<asp:listitem value= "3" text= "Audi car" ></asp:ListItem>
<asp:listitem value= "4" text= "Hyundai Motor" ></asp:ListItem>
<asp:listitem value= "5" text= "Toyota Motor" ></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:button id= "btnsubmit" runat= "Server" text= "Submit"/>
</td>
</tr>
</table>
</fieldset>
<div id= "message" class= "Alertmsg" >
</div>
</div>
</form>

The DropDownList control property ToolTip is converted to a Title,title value that can be used as a notification for the validation rule required, and the value CssClass of the property required specifies the plug-in's checksum rule.

Scripting code:
Copy Code code as follows:

<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>


Display effect:


In addition, if you do not set the DropDownList properties ToolTip and CssClass, the script code is changed as follows, and you can achieve the same effect:
Copy Code code as follows:

<script type= "Text/javascript" >
$ (function () {
$ ("#form1"). Validate ({
Rules: {dllcar: "required"},
messages: {dllcar: "Choose at least one car!" "},
Errorlabelcontainer: $ (" #message ")
});
});
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.