【发布时间】:2010-11-25 16:36:34
【问题描述】:
我正在构建我的第一个 ASP.net MVC 应用程序(不是我的第一个 jQuery 和 jQuery 验证插件应用程序),并且我在使用验证插件执行客户端验证时遇到了很糟糕的事情。有谁知道使用VS 2008自带的jQuery-1.3.2.min插件有问题吗?
我的代码如下:
var v = $("#frmAccount").validate({
rules: {
txtAccount: { minLength: 5,required: true },
txtFName: "required",
txtLName: "required"
},
message: {
txtAccount: {
required: "Account Number is required.",
minLength: jQuery.format("Account Number must be {0} or more charaters.")
},
txtFName: "First Name is required.",
txtLName: "Last Name is required.",
}
}); //validate
$("#cmd").click(function() {
if (v.form()) {
$("#frmAccount").submit();
}
});
.......................
当我尝试提交空白表单时,它会在帐户、fname 和 lname 字段旁边返回默认的“此字段是必需的”,但如果我在字段中输入任何数据,我会得到各种结果。
我尝试只执行基本的验证功能(不将验证对象返回给 v 变量),但这会产生类似的结果。
我只是在这里忽略了一些愚蠢的事情吗?
【问题讨论】:
标签: javascript jquery asp.net-mvc validation