<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>
javascript object对象存在与否-www.jb200.com</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") 
{ // 注意以上的 undefined 用于对象存在与否的比较
alert(strObj +" is an object"); 
} 
else 
{ 
alert(strObj +" is not an object"); 
} 
} 
//--> 
</script> 
</body>