ASP. NET jQuery instance 17 verifies ListBox by using the jQuery validation plug-in

Source: Internet
Author: User

Here, two ListBox rules are verified as an example:
• Verification required
• The selection range is from 0 ~ Four Items
Interface code: Copy codeThe Code is 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>
Select the car type:
</Td>
</Tr>
<Tr>
<Td>
<Asp: ListBox ID = "lstCar" runat = "server" Rows = "5" SelectionMode = "Multiple">
<Asp: ListItem Value = "1" Text = "Mercedes Benz"> </asp: ListItem>
<Asp: ListItem Value = "2" Text = "BMW"> </asp: ListItem>
<Asp: ListItem Value = "3" Text = "Audi"> </asp: ListItem>
<Asp: ListItem Value = "4" Text = ""> </asp: ListItem>
<Asp: ListItem Value = "5" Text = "Toyota"> </asp: ListItem>
</Asp: ListBox>
</Td>
</Tr>
<Tr>
<Td>
<Asp: Button ID = "btnSubmit" runat = "server" Text = "Submit"/>
</Td>
</Tr>
</Table>
</Fieldset>
<Div id = "message" class = "alertmsg">
</Div>
</Div>
</Form>

Script code:Copy codeThe Code is as follows: <Title> Recipe17 </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 ({
Rules :{
LstCar: {required: true, rangelength: [0, 4]}
},
Messages :{
LstCar: {required: "select at least one type of car! ",
Rangelength: "The selection range is 0 to four types of cars! "
}
},
ErrorLabelContainer: $ ("# message ")
});
});
</Script>
<Style type = "text/css">
. Alertmsg
{
Color: # FF0000;
}
</Style>
</Head>

Interface effect:

Related Article

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.