jQuery关闭表单验证 [英] jQuery turn off form validation

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

问题描述

我使用的是bog标准表单验证插件.我有两个单选按钮是"否",如果选中了是"单选按钮,我想做的就是设置验证...这是可行的,但是如果选择了否"单选按钮,则需要关闭验证.我正在尝试以下内容...

Im using the bog standard form validation plugin. I have two radio buttons 'yes' 'no' and what im trying to do is set validation if a radio 'yes' is checked... Which works, but i need to then turn off validation if the 'no' radio is selected. Im trying the following...

<script type="text/javascript">
    $(document).ready(function()
    {
        $('.cbyes').click(function() 
        {
            $('.hiddenDiv').show('slow');
            $("#regForm").validate();
        });
        $('.cbno').click(function() {
            $('.hiddenDiv').hide('slow');
            $('#regForm')[0].reset();
        });
    });
</script>

推荐答案

假设将验证应用于表单后,没有实际的方法可以关闭"验证,您可以使用validate方法,但是将其设置为忽略所有内容形式?

Assuming there's no practical way to "turn off" validation once it's been applied to a form, can you use the validate method, but set it ignore everything in the form?

$(document).ready(function()
{
    $('.cbyes').click(function() 
    {
        $('.hiddenDiv').show('slow');
        $("#regForm").validate();
    });
    $('.cbno').click(function() {
        $('.hiddenDiv').hide('slow');
        $('#regForm')[0].reset();
        $('#regForm').validate({
            ignore: "#regForm *"
        });
    });
});

此示例使用了一个愚蠢的通用选择器,应将其替换为更适合您特定形式的内容.

This example uses a dumb universal selector that should be replaced with something more appropriate for your particular form.

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

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