
本文教程操作环境:windows7系统、jquery3.2.1版本,DELL G3电脑。
方法一:判断length是否大于等于1
length大于等于1,则dom节点存在
Object.prototype.exist=function(){
if(typeofthis!='undefined'&&this.length>=1){
returntrue;
}
returnfalse;
};
方法二:使用document.getElementById方法判断
返回null则dom节点不存在
if(document.getElementById("map")){
console.log("存在");
console.log(document.getElementById("map"));
}else{
console.log("不存在");
console.log(document.getElementById("map"));
}原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
















































暂无评论内容