jQuery validator: Call method added with addMethod

爷,独闯天下 提交于 2019-12-12 12:20:57

问题


How I can call a validate method created with jQuery.validator?

Example:

jQuery.validator.addMethod("functionA", function(value, element) {
    if($.trim(value)==""){
        return false;
    }
    return true;
}, "MSG A");

jQuery.validator.addMethod("functionB", function(value, element) {
    return jQuery.functionA(); //<--- How do I do it?
}, "MSG B");

回答1:


Methods added with addMethod are inside the $.validator.methods object. You can call functionA like this:

jQuery.validator.addMethod("functionB", function(value, element) {
    return jQuery.validator.methods.functionA.call(this, value, element);
}, "MSG B");


来源:https://stackoverflow.com/questions/9038423/jquery-validator-call-method-added-with-addmethod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!