JS: How to make document.getElementById cross-browser?

后端 未结 4 712
清歌不尽
清歌不尽 2020-12-18 04:28

document.getElementById doesn\'t seem to work across all browsers (I mean some old ones) and I am sure there are developers who are not aware of this.

4条回答
  •  [愿得一人]
    2020-12-18 05:20

    getElemID(obj){
    
    if(document.getElementByID){
     return document.getElementByID(obj);
    }
    
     else if (document.all){
      return document.all[obj];
      }
    
      else if (document.layers){
         return  document.layers[obj];
         }
    
      else {
           alert("Could not find support");
           return false;
           }
    }
    

提交回复
热议问题