Compatible with IE getelementsbyclassname for tag obtaining

Source: Internet
Author: User

A friend provides online courses for an education institution of a state-owned enterprise in a company. Her job is to do some front-end page work, but the requirement for online courses is table layout, and IE6, 7, and 8 must be considered. jquery and other frameworks are not allowed. You need to know that IE does not support the use of classname to obtain tags. What if you want to use classname to obtain tags. You can use this method:

 Function Getelementsbyclassname (classname, root, tagname ){ //  Root: parent node, tagname: the label name of the node. Both parameters are optional.      If  (Root) {Root = Typeof Root = "string "? Document. getelementbyid (Root): root ;}  Else  {Root = Document. Body;} tagname = Tagname | "*";  If (Document. getelementsbyclassname ){ //  If the browser supports getelementsbyclassname, you can directly use          Return  Root. getelementsbyclassname (classname );}  Else  {  VaR Tag = root. getelementsbytagname (tagname ); //  Obtains the specified element.          VaR Tagall = [];//  Used to store qualified elements          For ( VaR I = 0; I <tag. length; I ++ ){ //  Traverse the obtained Elements              For ( VaR J = 0, n = tag [I]. classname. Split (''); j <n. length; j ++ ){ //  Traverses the values of all classes in this element. if it contains the specified class name, it is assigned to tagnameall.                  If (N [J] = Classname) {tagall. Push (TAG [I]); Break  ;}}}  Return  Tagall ;}} 

 

I remember my college website was still full of tables. The poor Internet is precisely the result of State-owned enterprises and ZF departments. I have been wondering why the Internet Banking of several large state-owned banks can only be accessed and paid by browsers with the IE kernel. Maybe they have their reasons. My knowledge is too small and I need to learn too much.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.