将字符串转化为布尔值的方法

<script>
function toboolean(val){
  switch (val.toLowerCase()){
    case "true": case 1: case "yes": return true;
    case "false": case 0: case "no": case null: return false;
    default:return Boolean(val);
  }
}
alert(toboolean("TRUE"))
</script>

posted @ 2018-08-16 15:13  古墩古墩  Views(7626)  Comments(0Edit  收藏  举报