if(document.getElementById(str))
{
  //do something
}

解决方案 »

  1.   

    function yul(str){
    if (document.all(str))
        alert('存在');
    else
        alert('不存在')
    }1)document.all(str) 亦可改为item方法 
    2)document.all.item(str)dom方法最通用
    3)document.getElementById(str)
      

  2.   

    var o=document.all('yourid')
    if(typeof(o)=="undefined"||o==null)alert('no found');
      

  3.   

    用阿信的方法没错:typeof 运算符把类型信息当作字符串返回。
    typeof 返回值有六种可能:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。
      

  4.   

    推荐typeof的方法,偶比较常用