JW.*_*JW. 1 javascript validation asp.net-mvc jquery
我正在构建我的第一个ASP.net MVC应用程序(不是我的第一个jQuery和jQuery Validation插件应用程序),我正在用验证插件执行客户端验证的可怕时间.有没有人知道使用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();
}
});
Run Code Online (Sandbox Code Playgroud)
............................
<form method ="post"action ="/ Home/checkAccount"id ="frmAccount">
< fieldset>
<legend>帐户信息</ legend>
<p>
<br />
<label for ="txtAccount">帐号:</ label>
<br />
<input id ="txtAccount"name ="txtAccount"type ="text"value =""/>
<br />
<label for ="txtFName">名字:</ label>
<br />
<input id ="txtFName"name ="txtFName"type ="text" value =""/>
<br />
<label for ="txtLName">姓氏:</ label>
<br />
<input id ="txtLName"name ="txtLName"type ="text"value ="" />
<br />
<label for ="txtLName">电子邮件:</ label>
<br />
<input id ="txtEmail"name ="txtEmail"type ="text"value =""/>
</ p >
<p>
<input type ="button"id ="cmd"name ="cmd"value ="Add"/>
</ p>
</ fieldset>
</ form>
当我尝试提交空白表单时,它返回帐户,fname和lname字段旁边的默认"此字段是必需的",但如果我在字段中输入任何数据,我会得到各种结果.
我试图只执行基本验证功能(不将验证对象返回到v变量),但这产生了类似的结果.
我只是忽略了一些愚蠢的东西吗?
Adrian Grigore,感谢您的快速回复.但是,我认为您可能忽略了上面发布的代码或其他内容. 也许你太忙于尝试插入自己的博客或其他东西.IDK.
REAL问题如下:
*在上面的代码"消息"应该是"消息s "
*另外,我做了(我考虑的)基本的MS编程背景错误...我camelCased工作minLength,并且(当然)在jQuery它应该是使用MINLENGTH
阿德里安,祝你好运!
| 归档时间: |
|
| 查看次数: |
1289 次 |
| 最近记录: |