【问题标题】:Disable and Enable jQuery Validation禁用和启用 jQuery 验证
【发布时间】:2014-01-20 08:09:29
【问题描述】:

如何使用按钮禁用或启用以下验证? pageload 加载如下函数,不知道怎么卸载。

    $(document).ready(function() {
        //* regular validation
        gebo_validation.reg();
});

    //* validation
    gebo_validation = {
        reg: function() {
            reg_validator = $('.form_validation_reg').validate({
                onkeyup: false,
                errorClass: 'error',
                validClass: 'valid',
                highlight: function(element) {
                    $(element).closest('div').addClass("f_error");
                },
                unhighlight: function(element) {
                    $(element).closest('div').removeClass("f_error");
                },
                errorPlacement: function(error, element) {
                    $(element).closest('div').append(error);
                },
                rules: {     
                        campaign_name: {
                                require_from_group: [1, '.span8'],
                                minlength: 3,
                                //notBoth: ['input[name="exist_campaign_name"]']
                        },
                        exist_campaign_name: {
                                require_from_group: [1, '.span8'],
                                minlength: 3,
                                //notBoth: ['input[name="campaign_name"]']
                        },
                },
                invalidHandler: function(form, validator) {
                    $.sticky("There are some errors. Please correct them and submit again.", {autoclose : 5000, position: "top-right", type: "st-error" });
                }
            });

            $('.span8').on('blur', function () {
                if ($(this).val() != '') {
                    $('.span8').not(this).prop('disabled', 'disabled');
                } else {
                    $('.span8').not(this).removeProp('disabled');
                }
            });

            //Some extra validation methods.
            /* jQuery.validator.addMethod('notBoth', function (value, element, param) {
                return ((value != '') && ($(param[0]).val() == '') || (value == '') && ($(param[0]).val() != ''));
            }, "Please do not fill out both fields"); */    
        }
    };

【问题讨论】:

标签: javascript jquery


【解决方案1】:

我在这里找到了解决方案..jQuery validate - set conditional rules based on user selection

使用示例代码:

$('#myform').validate({
    rules: {
        fieldA: {
           required:'#checkA:checked'
        }
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多