首页 > 编程 > JavaScript > 正文

js 对象是否存在判断

2019-11-21 01:16:12
字体:
来源:转载
供稿:网友
复制代码 代码如下:

<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>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表