jQuery表单验证问题 [英] Jquery form validation issue

查看:63
本文介绍了jQuery表单验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Validate作为我网站的联系表单.输入字段具有预先填充的默认值,即名称"是人们应该在其中键入姓名的文本字段的默认值.

I’m using jQuery Validate for my site’s contact form. The input fields have pre-populated default values, i.e. "Name" is the default value for the text field where people should type their name.

其中一些字段是必需的,但是jQuery Validate的基本设置仅检查字段中是否有内容,而不是内容.我的问题是,即使人们没有输入他们的姓名,该表单也仍然有效,因为该字段中仍然存在姓名"的默认值.

Some of these fields are required, but the basic set-up of jQuery Validate only checks if there is content in the fields, not what the content is. My problem is that even if people don’t enter their name, the form will still validate because the default value of "Name" still exists in the field.

有人知道我如何编程jQuery验证以检查默认值,如果存在默认值,则返回错误消息?

Does anyone know how I can program jQuery validate to check for the default values, and if they exist, to return an error message?

感谢您的帮助!

推荐答案

我会使用valid = function(inputValue){ return true; }

来自文档

设置在检查输入时认为有效的值.对于有效输入,该函数返回true;对于无效输入,该函数返回false.

Set the values that are considered valid when the input is checked. The function returns true for valid input and false for invalid input.

所以你会做类似的事情

$('myform').validate({ valid: function(input){
    // check input value against your default values
    // - If match, return false (is NOT valid)
    // - If no match, return true (is valid)
});

这篇关于jQuery表单验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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