您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

javascript怎么判断id是否存在

2024/3/22 21:48:21发布23次查看
javascript判断id是否存在的方法:1、创建一个html示例文件;2、添加script标签;3、通过“function exist(id){...}”方法判断id是否存在即可。
本文操作环境:windows7系统、javascript1.8.5版、dell g3电脑。
javascript怎么判断id是否存在?
js 判断id 是否存在的方法
代码如下:
<!doctype html><html><head><meta charset="utf-8"><title>document</title><script type="text/javascript">// window.onload=function(){// alert(exist("getspantext"));// alert(exist("111"))// }function loadtext(){alert(exist("getspantext"));}function exist(id){var s=document.getelementbyid(id);if(s){return true}else{return false}}</script></head><body onload="loadtext()"><span id="getspantext">jason</span》</body></html>
【推荐学习:javascript基础教程】
以上就是javascript怎么判断id是否存在的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product