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

jQuery方法:

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

 

Javascript原生:

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

 

相关文章:

  • 2022-03-05
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-12-18
  • 2022-12-23
相关资源
相似解决方案