How to convert string into boolean?

This question already has an answer here:

  • How can I convert a string to boolean in JavaScript? 71 answers

  • Try

    <div id='test' data-nav='true'>
    
    
    var truefalse = $('#test').data('nav');
    

    .data should be able to evaluate it as boolean

    here is an example in JSFiddle https://jsfiddle.net/lismore/hx3gLvgw/

    链接地址: http://www.djcxy.com/p/75084.html

    上一篇: 为什么使用JavaScript eval函数是一个坏主意?

    下一篇: 如何将字符串转换为布尔值?