我想将字符串变量转换为 bool 值。
当我分配一个没有变量的属性时,它正在工作:
.Set( 'bevel', false ) // working
现在我想通过这样的变量分配它:
function abc(prop){
.Set( 'bevel', prop ) // not working
.Set( 'bevel', Boolean(prop) ) // this is also not working
}
最佳答案
var prop = 'true';
应该不加引号
var prop = true;
将 bool 值与字符串一起使用,它将返回 true,就好像它是字符串一样,并且包含字符串结果为 true
Boolean('true');//true
Boolean('false');//true
关于Javascript:通过变量分配 bool 属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25198655/