Welcome 微信登录

首页 / 脚本样式 / JavaScript / 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>