Trigger variable true or false
I have a simple page with few tabs. The tabs work if disable_function = false otherwise if true then they do not work. The code for the tabs is:
var disable_function = false;
jQuery('.tabs a').click(function() {
if (!disable_function ){
var ref = jQuery(this).attr('href').split('#')[开发者_开发技巧1];
jQuery('div.tab_content:not(#' + ref + ')').hide();
jQuery('#' + ref).fadeIn();
return false;
}
});
In this page I also have a trigger which I want it, IF the trigger is on then set var disable_function = true;
The code for the trigger is:
$('#1').Switch("off", function () {
});
I tried by inserting var disable_function = true; but it doesn't seem to set it as true. I even tried set var disable_function = true;
Im pretty sure this is quite simple but I'm new in jquery.
Thanks alot
You need to learn javascript before jQuery. I hope i've understood the question anyway this should work:
$('#1').Switch("off", function () {
disable_function = true;
});
if you use var disable_function = true;
you declare a new variable named disable_function
inside the function scope instead of assign a value to the variable in the global scope.
It is a little difficult to determine what you are asking. Are you just trying to change the value of the disable_function
variable? If so, you do not need to use var
again:
var disable_function = false;
// later change the value //
disable_function = true;
精彩评论