jQuery Validation插件-验证隐藏的输入并且不可见? [英] jQuery Validation plugin - Validating hidden inputs and not visible?

查看:71
本文介绍了jQuery Validation插件-验证隐藏的输入并且不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery Form Validation插件验证隐藏的输入和不可见的文本输入?问题是,我使用的是自动建议插件,该插件会为选定的项目生成隐藏的输入:

How would I validate hidden inputs and not visible text inputs with jQuery Form Validation plugin? The problem is, that I'm using auto-suggest plugin, which generates a hidden input for selected items:

<input id="hiddenInput" type="hidden" name="something" value="1" />

我有2个像这样的输入(它们都只允许1个输入),我想验证这些输入并在父级<td>中显示错误. 到目前为止,这就是我所得到的,但是如果值实际上是一个数字,它不会显示错误或提交表单.

I have 2 inputs like this (both of them only allow 1 item), which I want to validate and display the error in parent <td>. This is what I've gotten so far, but it doesn't display the error or submit a form, if the value is actually a number.

$("#form1").validate({
        rules: {
            something: {
                number:true,
                min:1,
                required:true
            }
        }
        })

推荐答案

要允许验证隐藏元素,请覆盖忽略并将其设置为空字符串:

To allow validation of hidden elements, override the ignore and set it to empty string:

$("#form1").validate({
    ignore: "",
    rules: {
        something: {
            number:true,
            min:1,
            required:true
        }
    }
});

这篇关于jQuery Validation插件-验证隐藏的输入并且不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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