文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php教程>javascript怎么判断id是否存在

javascript怎么判断id是否存在

时间:2021-11-13  来源:互联网

今天PHP爱好者为您带来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怎么判断id是否存在的详细内容,更多请关注php爱好者其它相关文章!

相关阅读更多 +
最近更新
排行榜 更多 +
元梦之星最新版手游

元梦之星最新版手游

棋牌卡牌 下载
我自为道安卓版

我自为道安卓版

角色扮演 下载
一剑斩仙

一剑斩仙

角色扮演 下载