if(document.all('id') != null) alert('ok')

解决方案 »

  1.   

    if (document.getElement("xxx"))
     {
      //your code;
      }
      

  2.   

    try{if(typeof xxx=="object")
           //do something your codes
    }
    catch(e)
    {alert("Not a such object!")}
      

  3.   

    try{
    if (document.all("id")!=null){
    ....}}
    catch(e){
    alert("not exists")}
      

  4.   

    最好它的id = xxx  name = xxx
    if (xxx)
       alert("OK");
    else
       alert("!OK");
      
    或者
    if(typeof (xxx)=="object")
        alert("OK");
    else
       alert("!OK");
      

  5.   

    <SCRIPT LANGUAGE="JavaScript">
    if(document.getElementById("d")==null)alert("对象不存在")
    </SCRIPT>