开发者

Overriding a global variable in Javascript

开发者 https://www.devze.com 2023-04-05 05:19 出处:网络
$(doc开发者_开发问答ument).ready(function(){ var min=\"1.2.2\"; $.validator.addMethod(\'xyz\', function(value, element, param) {
$(doc开发者_开发问答ument).ready(function(){    
        var min="1.2.2";          
        $.validator.addMethod('xyz', function(value, element, param) {        
                        alert(min);    
                        min=minAorB();// I want to call a function which will return the minimum among A and B.  
                        alert(min);    
                        return (validateAnmcComp(value,param));    
                        }, "Please enter a value less than or equal to "+min);  
        })(jQuery);  

I want the message to be displayed as "Please enter a value less than or equal to 1.4.5"


Would this help?

$(document).ready(function($) {
    function createMinValidator(min) {
        return function(value, element, param) {
            // use min as required
            return (validateAnmcComp(value, param));
        };
    }
    var min = "1.4.5";
    var msg = "Please enter a value less than or equal to " + min;
    $.validator.addMethod('xyz', createMinValidator(min), msg);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消