Boolean(“false”) returns true.. any alternative?

前端 未结 2 1904
梦毁少年i
梦毁少年i 2021-01-28 11:58

I am using jquery to write true and false strings to data- html attributes. However when I write false to one of the attributes, and then check it it false, it returns true. I a

2条回答
  •  失恋的感觉
    2021-01-28 12:34

    The simplest fix would be:

    var is_activate = $(this).attr("data-is-panel-activated") !== "false";
    

    or

    var is_activate = $(this).attr("data-is-panel-activated") === "true";
    

    depending on which semantics makes more sense for your code.

提交回复
热议问题