gpt4 book ai didi

javascript - 如何在javascript中将字符串转换为 bool 值?

转载 作者:行者123 更新时间:2023-11-29 16:06:11 24 4
gpt4 key购买 nike

我有一个公共(public)属性从我的代码隐藏类返回到 aspx 页面:

window.MyWIndow.IsFull = '<%=this.IsFull%>';

在代码隐藏中它是这样定义的:

public bool IsFull
{
get;
set;
}

现在,当我在我的 javascript 文件中使用它时,我有以下代码:

var isShow = myself.IsFull;

这样 isShow 要么是 'True' 要么是 'False'

我需要在页面级别转换它,所以 isShowboolean 而不是 string

所以我可以写if else逻辑

我该怎么做?

最佳答案

您可以使用 JSON.parse('true');

JSON.parse(isShow.toLowerCase());

试试下面的例子。

var result = ['True', 'False']

var isShow = result[Math.round(Math.random())];

console.log(JSON.parse(isShow.toLowerCase()));

关于javascript - 如何在javascript中将字符串转换为 bool 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41731287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com