if(typeof objName == "undefined")
   alert("不存在");

解决方案 »

  1.   

    typeof 运算符
    请参阅
    运算符优先级 | 运算符总结
    要求
    版本 1
    返回一个用来表示表达式的数据类型的字符串。typeof[()expression[]] ;
    expression 参数是需要查找类型信息的任意表达式。说明
    typeof 运算符把类型信息当作字符串返回。typeof 返回值有六种可能:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。typeof 语法中的圆括号是可选项。
      

  2.   

    <div id=div1></div>
    <input type=button onclick=if(getElementById("div1")!=null)alert("存在")>
      

  3.   

    <div id=div1></div>
    <input type=button onclick=if(getElementById("div1")!=null)alert("存在")>