清除输入字段(如果无效) [英] clearing a input field if it is invalid

查看:91
本文介绍了清除输入字段(如果无效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用验证插件.我试图弄清楚如果该字段无效,如何清除文本字段.

i am using validation plugin. i am trying to figure out how to clear a text field, if the field is invalid .

我的JavaScript代码如下

my javascript code is as follows

$(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的字段.可以在validate函数中做到这一点吗?

I am trying to clear out the field called offer_code if the field is invalid. is it possible to do this with in the validate function?

亚历克斯

推荐答案

检查一下:

http://docs.jquery.com/Plugins/Validation/valid

示例:

$(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"
        }
    }
});});

$("#enrollForm").blur(function() {
  if($("#enrollForm").valid()) {
    //success code?
  } else {
    $("#enrollForm").val('')
  }
});

这篇关于清除输入字段(如果无效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆