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

前端 未结 2 1903
梦毁少年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:45

    Boolean('false') will return true because the string 'false' is truthy.

    You could just run a check to see if the string equals 'false':

    if ($(this).attr("data-is-panel-activated") === 'false') {
       .....
    }
    

提交回复
热议问题