2012-01-27 64 views
4

我如何調用使用jQuery.validator創建的驗證方法?jQuery驗證程序:通過addMethod添加調用方法

實施例:

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"); 

回答

8

方法加入addMethod$.validator.methods對象內部。你可以這樣撥打functionA

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