我正在汇集一些隐藏字段中的以下值。
var hfEntityBool = $(this).find('input[id*="hfEntityBool"]').val();
if (hfEntityBool) {
alert(hfEntityBool);
}
无论隐藏字段的值是什么,警报仍然会显示。有什么理由吗?
我尝试使用 Boolean(hfEntityBool) 方法以防隐藏字段仍然是字符串,但没有任何变化。
感谢您的帮助
最佳答案
这取决于您在隐藏字段中期望的值。
我会做这样的事情:
var hfEntityBool = $(this).find('input[id*="hfEntityBool"]').val() == "true";
if (hfEntityBool) {
alert(hfEntityBool);
}
关于Jquery:将字符串转换为 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17841768/