Home >Web Front-end >HTML Tutorial >查找html元素_html/css_WEB-ITnose

查找html元素_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:38:011318browse

一、

     通过id找到html元素

     document.getElementById();

 

二、

     通过标签名查找html元素

     document.getElementsByTagName();

 

三、

     通过类名查找html元素

     function getByClass(oparent, oclass){

     var aEle = oparent.getElementsByTagName("*");
     var i = 0;
     var aResult = [];
     for(i=0; i           if(aEle[i].className == oclass){
               aResult.push(aEle[i]);
          }
     }
     return aResult;

     }

ps:以上的document也可以换成object,它是查找在自己的子系元素

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn