How to check 'undefined' value in jQuery

后端 未结 11 572
慢半拍i
慢半拍i 2020-12-12 11:49

Possible Duplicate:
Detecting an undefined object property in JavaScript
javascript undefined compare

H

11条回答
  •  攒了一身酷
    2020-12-12 12:08

    when I am testing "typeof obj === undefined", the alert(typeof obj) returning object, even though obj is undefined. Since obj is type of Object its returning Object, not undefined.

    So after hours of testing I opted below technique.

    if(document.getElementById(obj) !== null){
    //do...
    }else{
    //do...
    }
    

    I am not sure why the first technique didn't work.But I get done my work using this.

提交回复
热议问题