Retrieve boolean data from data attribute in jquery

后端 未结 5 664
梦如初夏
梦如初夏 2020-12-14 05:34

I am trying to retrieve a data attribute of type Boolean from an html DIV element , however it is always returning false when the string is converted to boolean .

H

5条回答
  •  臣服心动
    2020-12-14 05:52

    "true" is internally casted to boolean (try alert (typeof(isreturn_str))), hence your === comparison fails on type check.

    You could call .toString()

    isreturn_str = $('#test').data('return').toString();
    

    http://jsfiddle.net/494wC/8/

提交回复
热议问题