Tuesday 15 September 2015

javascript - Why is jquery toggle not working? -


I just want to toggle a variable between right and wrong and have text on button It's my junkie clicked to change the form as well:

  $ ("button"). Toggle (function () {$ (this) .text ("click to paint brush"); var erasing = true;}, function () {$ (this) .text ("Click to change in eraser" Do "); var erasing = false;});   

This looks 100% sound for me, but in me you will see that before I can click here, before that the existence of the button is being toggled! Why is this happening and how can I fix it?

This version toggle has been deprecated (1.8) and deleted (1.9 ). Now you need to click it on the button. Something like this:

  var erasing = false; Click $ ("button") (function () {erasing =! Erasing; $ (this) .text (function (_, curText) {return curText == "Click to change color brush"? " Click "Eraser": "Click to paint a brush";}); console.log (erasing ;;});   

Plus If you want to preserve the value of the variable, then it is only defined by the scope of the click event, so that it is more global to be externally. < / Strong>

No comments:

Post a Comment