我有一个公共属性从我的代码隐藏类返回到aspx
页面:
window.MyWIndow.IsFull = '<%=this.IsFull%>';
在代码背后,它是这样定义的:
public bool IsFull
{
get;
set;
}
现在,当我在javascript文件中使用它时,我有以下代码:
var isShow = myself.IsFull;
这样,isShow
要么是'True'
,要么是'False'
我需要在页面级别上转换它,所以isShow
是boolean
而不是string
。
所以我可以写if else
逻辑
我该怎么做呢?
发布于 2017-01-18 15:32:40
您可以使用JSON.parse('true');
JSON.parse(isShow.toLowerCase());
试试下面的例子。
var result = ['True', 'False']
var isShow = result[Math.round(Math.random())];
console.log(JSON.parse(isShow.toLowerCase()));
发布于 2017-01-18 15:33:27
如果你知道它总是会返回字符串真假,你可以用;
window.MyWindow.IsFull = '<%=this.IsFull%>' === "True";
发布于 2017-01-18 15:44:17
替代方法是
window.MyWIndow.IsFull = <%=this.IsFull.ToString().ToLower()%>;
注意,没有引号
https://stackoverflow.com/questions/41731287
复制相似问题