javascript 中判断页面对象是否存在
在写javascript时经常想知道html中的一个对象是否存在?或者页面上不想报找不到对象的javascript错误代码如下:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>javascript object</title><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></head><body> <input id="aaa"> <input type=buttonvalue="checkaaa"> <input type=buttonvalue="checkother"></body></html>
页:
[1]