转载自 https://blog.csdn.net/lpandeng/article/details/78455907
if(document.getElementById("id")){
alert(‘对象存在‘); ... ...
} else{
alert(‘对象不存在‘); ... ...
}
多个页面共用一个js文件,但是有些页面没有某个元素,导致报错
原文:https://www.cnblogs.com/Z7TS/p/12416971.html