WebLinuxStudy

导航

 

只需要判断指定ID对象的length是否大于0

jQuery方法:

if ($("#ID").length > 0) {
  alert('对象存在');
}else
  alert('对象不存在');
}

 

Javascript原生:

if (document.getElementById("ID")) {
  alert('对象存在');
} else {
  alert('对象不存在');
}

 

posted on 2020-10-15 16:42  WebLinuxStudy  阅读(1500)  评论(0)    收藏  举报