js判断网页中某个id是否存在的代码
发布时间:2014-10-22 编辑:jiaochengji.com
本文介绍一个可以判断网页中某id元素是否存在的js代码,有需要的朋友,可以参考下。
代码如下:
复制代码 代码示例:
<html>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>判断某元素id是否存在-www.jiaochengji.com</title>
<link rel="stylesheet" type="text/css" href="" media="all" />
<script type="text/javascript">
function exist(id){
var s=document.getElementById(id);
if(s){return true}
else{return false}
}
window.onload=function(){
alert(exist("wrapper"));
alert(exist("111"))
}
</script>
</head>
<body>
<div id="wrapper"></div>
</body>
</html>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>判断某元素id是否存在-www.jiaochengji.com</title>
<link rel="stylesheet" type="text/css" href="" media="all" />
<script type="text/javascript">
function exist(id){
var s=document.getElementById(id);
if(s){return true}
else{return false}
}
window.onload=function(){
alert(exist("wrapper"));
alert(exist("111"))
}
</script>
</head>
<body>
<div id="wrapper"></div>
</body>
</html>
您可能感兴趣的文章:
js判断网页中某个id是否存在的代码
shell根据pid判断进程是否存在
用JQuery 判断某个属性是否存在hasAttr的解决方法
js判断图片是否被缓存的一例代码
如何用Jquery判断iframe中元素是否存在
WordPress常用的函数、方法汇总
js判断背景图片是否加载成功的简单方法
jQuery如何判断页面元素是否存在
让jQuery Mobile不显示讨厌loading界面的方法
php怎么判断页面是否微信打开
[关闭]