如果输入字段无效,则清除该输入字段
我正在使用验证插件。我试图弄清楚如何清除文本字段(如果该字段无效)。
我的 JavaScript 代码如下,
$(document).ready(function() {
$("#enrollForm").validate({
rules: {
email: {
required: true,
email: true
},
vemail: {
required: true,
email: true,
equalTo: "#email"
},
offer_code: {
required: false,
remote: "check_code.php"
}
}
});});
如果该字段无效,我会尝试清除名为 Offer_code 的字段。是否可以在验证函数中执行此操作?
亚历克斯
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看这个:
http://docs.jquery.com/Plugins/Validation/valid
例子:
Check this out:
http://docs.jquery.com/Plugins/Validation/valid
The example:
我使用 jquery 来验证一些表单。例如,在我的网站上,有一个部分用户必须输入然后重新输入密码。如果他们的第二个密码的值等于他们的第一个密码,我使用 jquery 向下滑动一个 div,上面写着“您的密码匹配!”
试试这个:
那里有很多代码。但是,它还根据长度要求验证了表单。如果密码少于 4 个字符,系统会在用户输入密码时发出通知。
你明白了......希望这有帮助
I have used jquery to validate a few forms. For instance, on my site, there is a part where a user has to enter and then re-enter their passwords. If the value of their second password is equal to their first password, I use jquery to slide down a div that says "Your passords match!"
Try this:
There is a lot of code there. But, it also validates the form in terms of length requirements. If the password is less than 4 characters, it notifies them as they're entering their password.
You get the idea.... Hope this helps
假设插件为
input
分配了一个label
,并且具有error
类,那么您可以这样做:更准确一点,因为验证插件还为错误标签分配了一个
for
属性:我假设“验证插件”指的是这个,位于:http://bassistance.de/jquery-plugins/jquery-plugin-validation/,如果我错了那么这个,显然,可能行不通。
Assuming that the plugin assigns a
label
for theinput
with a class oferror
, then you could do this:To be a little more accurate, since the validation plugin also assigns a
for
attribute to the error labels:I'm assuming, by 'validation plugin' that you mean this one, at: http://bassistance.de/jquery-plugins/jquery-plugin-validation/, if I'm wrong then this, obviously, might not work.