📌  相关文章
📜  检查id是否存在javascript代码示例

📅  最后修改于: 2022-03-11 15:03:01.258000             🧑  作者: Mango

代码示例1
var myEle = document.getElementById("myElement");
    if(myEle){
        var myEleValue= myEle.value;
    }

//the return of getElementById is null if an element is not actually 
//present inside the dom, so your if statement will fail, because null 
//is considered a false value