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>