jquery validation插件 - 控制自定义范围文本框重叠

时间:2014-03-31 18:59:11

标签: javascript jquery jquery-plugins jquery-validate

lower: {
    minlength: 1,
    maxlength: 4,
    required: true,
    digits: true,
    between: ['#pLower', '#pUpper']
},
upper: {
    minlength: 1,
    maxlength: 4,
    required: true,
    digits: true,
    greaterThan: '#lower',
    between: ['#pLower', '#pUpper']
},
pLower: {
    minlength: 1,
    maxlength: 4,
    required: true,
    digits: true,
    between: ['#lower', '#upper']
},
pUpper: {
    minlength: 1,
    maxlength: 4,
    required: true,
    digits: true,
    greaterThan: '#pLower',
    between: ['#lower', '#upper']
}

我有两个自定义函数,其中一个更好的工作正常但检查两个范围之间的重叠对我来说是一个问题。如果必须检查底部和底部之间的前两个文本框与第一个。因此,如果最高者有1和50.它将不允许在其他人中写入25和75。


$.validator.addMethod("greaterThan", function (value, element, param) {
    var $min = $(param);

    if (this.settings.onfocusout) {
        $min.off(".validate-greaterThan").on("blur.validate-greaterThan", function () {
            $(element).valid();
        });
    }

    return parseInt(value) > parseInt($min.val());
}, "upper must be greater than lower");

$.validator.addMethod("between", function (value, element, param) {
    var $min = $(param[0]);
    var $max = $(param[1]);

    if (this.settings.onfocusout) {
        $min.off(".validate-between").on("blur.validate-between", function () {
            $(element).valid();
        });
    }
    return parseInt(value) < parseInt($min.val()) || parseInt(value) > parseInt($max.val());
}, "values must not overlap");
}

http://jsfiddle.net/walidmalik/4ERP7/

0 个答案:

没有答案