ASP.NET jQuery 实例17 通过使用jQuery validation插件校验ListBox - Web前端
作者:98wpeu发布时间:2026-10-05分类:网页前端技术浏览:85
导读:这里我们举例校验listBox两个规则:•校验必选项•选择范围在0~4项界面代码:复制代码代码如下:<FORMid="form1"runat="server"&...
这里我们举例校验listBox两个规则:
•校验必选项
•选择范围在0~4项
界面代码:
复制代码 代码如下:
<FORM id="form1" runat="server">
<div align="center">
<fieldset style="width: 350px; height: 200px;">
<tableborder="0" cellpadding="3" cellspacing="3">
<tr>
<td>
请选择汽车类型:
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="lstCar" runat="server" Rows="5" selectionmode="Multiple">
<asp:ListItemvalue="1" text="奔驰汽车"></asp:ListItem>
<asp:ListItem Value="2" Text="宝马汽车"></asp:ListItem>
<asp:ListItem Value="3" Text="奥迪汽车"></asp:ListItem>
<asp:ListItem Value="4" Text="现代汽车"></asp:ListItem>
<asp:ListItem Value="5" Text="丰田汽车"></asp:ListItem>
</asp:ListBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="BTnSubmit" runat="server" Text="提交" />
</td>
</tr>
</table>
</fIEldset>
<div id="message" class="alertmsg">
</div>
</div>
</Form>
脚本代码:
复制代码 代码如下:
<head id="Head1" runat="server">
<title>Recipe17</title>
<scripttype="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: "至少选择一种车!",
rangelength: "选择的范围为零到四种车!"
}
},
errorlabelContAIner: $("#message")
});
});
</script>
<style type="text/CSS">
.alertmsg
{
color: #FF0000;
}
</style>
</head>
界面效果:
•校验必选项
•选择范围在0~4项
界面代码:
复制代码 代码如下:
<FORM id="form1" runat="server">
<div align="center">
<fieldset style="width: 350px; height: 200px;">
<tableborder="0" cellpadding="3" cellspacing="3">
<tr>
<td>
请选择汽车类型:
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="lstCar" runat="server" Rows="5" selectionmode="Multiple">
<asp:ListItemvalue="1" text="奔驰汽车"></asp:ListItem>
<asp:ListItem Value="2" Text="宝马汽车"></asp:ListItem>
<asp:ListItem Value="3" Text="奥迪汽车"></asp:ListItem>
<asp:ListItem Value="4" Text="现代汽车"></asp:ListItem>
<asp:ListItem Value="5" Text="丰田汽车"></asp:ListItem>
</asp:ListBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="BTnSubmit" runat="server" Text="提交" />
</td>
</tr>
</table>
</fIEldset>
<div id="message" class="alertmsg">
</div>
</div>
</Form>
脚本代码:
复制代码 代码如下:
<head id="Head1" runat="server">
<title>Recipe17</title>
<scripttype="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: "至少选择一种车!",
rangelength: "选择的范围为零到四种车!"
}
},
errorlabelContAIner: $("#message")
});
});
</script>
<style type="text/CSS">
.alertmsg
{
color: #FF0000;
}
</style>
</head>
界面效果:

相关推荐
- WordPress 应用:如何修改模版头部文件中的 wp_head() - Web前端
- SEO 优化:YouTube SEO Plugin 提升影片流量 - Web前端
- 使用 React 服务器组件在 Next.js 13 中进行国际化 - Web前端
- 3 个意想不到的技术 SEO 问题示例(以及如何解决它们) - Web前端
- Vue 技术专题:Suspense、路由模式与单元测试实践 - Web前端
- 如何防止 WordPress SQL 注入攻击? - Web前端
- SEO 优化:如何围绕技术SEO框架以构建和制定策略? - Web前端
- SEO优化:YouTube SEO 关键词研究工具 - Web前端
- 2025 年帮助代理机构提升客户业绩的 14 款最佳 SEO 工具 - Web前端
- 客户端:服务器之间设置本地 DNS 服务器 - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 4【第六章】Foundation之按钮和下拉功能 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 9jQuery编写widget的一些技巧分享 - Web前端
- 最近发表
-
- WordPress 应用:如何修改模版头部文件中的 wp_head() - Web前端
- SEO 优化:YouTube SEO Plugin 提升影片流量 - Web前端
- 使用 React 服务器组件在 Next.js 13 中进行国际化 - Web前端
- 3 个意想不到的技术 SEO 问题示例(以及如何解决它们) - Web前端
- Vue 技术专题:Suspense、路由模式与单元测试实践 - Web前端
- 如何防止 WordPress SQL 注入攻击? - Web前端
- SEO 优化:如何围绕技术SEO框架以构建和制定策略? - Web前端
- SEO优化:YouTube SEO 关键词研究工具 - Web前端
- 2025 年帮助代理机构提升客户业绩的 14 款最佳 SEO 工具 - Web前端
- 客户端:服务器之间设置本地 DNS 服务器 - Web前端


