js 对象是否存在判断


复制代码 代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>javascript object</title>
<body>
<input id="aaa">
<input type=button onclick="check('aaa')" value="checkaaa">
<input type=button onclick="check('aaffdssfg')" value="checkother">
<script language="javascript">
<!--
function check(strObj)
{
if(typeof(eval("document.all."+strObj))!= "undefined")
{
alert(strObj +" is an object");
}
else
{
alert(strObj +" is not an object");
}
}
//-->
</script>
</body>

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3