我剥离了我的所有逻辑出我的jquery插件这个问题,但我的问题是,当我调用我的函数checkValidationName,它这样做的事情,并将名称=设置为true。然后,当我尝试在我称之为的地方进行比较时,该值是错误的。为什么是这样?jquery插件函数返回值
(function($){
$.fn.validate = function() {
var name = false;
$('.submitBtn').click(function() {
$.fn.validate.checkValidationName(nameValues);
**console.log("name = "+name); **//but this prints out "false"****
//shouldn't this be true since name returned true in the actual function??
}
});
$.fn.validate.checkValidationName = function(id) {
$.post("PHP/submitButtonName.php", {checkValidation: id},
function(data) {
**console.log("name = "+name); **//this prints out "true"****
//name is equal to true here
}, "json");
};
}
})(jQuery);
有没有办法保持名称的价值并将其用于不同的功能?我有3个类似于checkValidationName的函数全部使用不同的变量,我想比较所有的变量,并执行一个操作,如果所有3遍都是有效的,而不仅仅是一个。 – Catfish 2010-02-08 17:01:23
你可以做一些像http://pastie.org/817909。 如果你需要做一些事情,如果不是所有东西都是有效的,你需要跟踪doStuffIfAllValid()被调用了多少次。 – jou 2010-02-10 09:36:22