本文介绍了jQuery验证仅验证一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery验证来验证表单。我的表单上有两个文本框,只有第一个会添加此字段是必填项。信息。如果我从第一个中删除required类,则第二个将有消息。
I am using jQuery validate to validate a form. I have two text boxes on my form and only the first one will add the "This field is required." message. If I remove the "required" class from the first one the second will have the message.
html:
<form id="questionForm">
<div><input class="required" id="value" type="text" /></div>
<div><textarea class="required" id="description"></textarea></div>
<button type="submit">Save</button>
</form>
javascript:
javascript:
$("#questionForm").validate({ submitHandler: function() {
alert("valid");
}
});
为什么只有一个被验证?
Why is only one being validated?
编辑:我正在使用jQuery验证插件1.7
I'm using jQuery validation plug-in 1.7
- http://bassistance.de/jquery-plugins/jquery-plugin-validation/
- http://docs.jquery.com/Plugins/Validation
编辑2:我正在使用MVC 3
Edit 2: I'm using MVC 3
推荐答案
我刚跑了自己进入这个问题。把我的头发拉了一个小时,但现在是:
I just ran into this issue myself. Pulled my hair out for an hour, but here it is:
将name属性扔进去那里也可以做到这一点。
Throw the "name" attribute in there as well and that may do the trick.
这篇关于jQuery验证仅验证一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!