2

I'm pooling the following values from some hidden fields.

var hfEntityBool = $(this).find('input[id*="hfEntityBool"]').val();
if (hfEntityBool) {
    alert(hfEntityBool);
}

No matter what the value of the hidden field, the alert still displays. Any reason for that?

I've tried to use Boolean(hfEntityBool) method in case the hidden field's still a string, but nothing changed.

Thank for helping

4

2 回答 2

5

这取决于您在隐藏字段中期望的值。

我会做这样的事情:

var hfEntityBool = $(this).find('input[id*="hfEntityBool"]').val() == "true";
if (hfEntityBool) {
    alert(hfEntityBool);
}
于 2013-07-24T18:19:51.007 回答
0

你试过了吗 :

if(hfEntityBool.length){...} // (or hfEntityBool.length > 0)

控制台为此显示了什么:

console.log('nb char of hfEntityBool : '+hfEntityBool.length);//before if
于 2013-07-24T18:22:17.730 回答