开发者

How to toggle a variable from true to false

I have this setup: http://jsfiddle.net/patrioticcow/yJPGa/5/

I can't figure out how how to toggle in between a true or false variable. Here is the code:

<div class="test" id="id_test">Some Content...</div>
<div style="display: none" id="id_test">Some Other Content...</div>
<div>
  <button id="disable">Save</button>
  <button id="enable">Edit</button>
</div>

js

var logged_in = false;

$("#disable").click(function() {
  logged_in == true;
  alert (logged_in);
});

$("#enable").click(function() {
  logged_in == false;
  alert (logged_in);
});

if (logged_in == true) {
  $("#id开发者_如何学Python_test").find(".test").removeClass(".test").addClass(".test_hidde");
}

css

.test{color: red;font-size: 16px;}
.test_hidde{color: #000;font-size: 26px;}


logged_in = !logged_in

Will do the trick.

Also, these two lines are the same:

if (logged_in == true)
if (logged_in)


Here ya go in a fiddle: http://jsfiddle.net/maniator/yJPGa/7/

changed the lines: logged_in == true; ==> logged_in = true;
and logged_in == true; ==> logged_in = false;

== denotes boolean check whereas = sets something as equal to something else


Here is a fiddle with the if statement fixed: http://jsfiddle.net/maniator/yJPGa/8/

The statement has to be encapsulated in a function

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜