Implement tab tab switch based on JavaScript _javascript tips for special effects debugging notes

Source: Internet
Author: User

This article examples for everyone to analyze the JavaScript implementation tab tab switch debugging notes, for your reference, the specific contents are as follows

When you make a navigation bar, clicking on the navigation bar element produces a corresponding change, and the element displays a special style.

JS Source code:

Navigation bar Click Transform Content
function Tabswitch (_this,num) {
 var tag = document.getElementById ("nav9");
 var number = Tag.getelementsbytagname ("a"); Gets the number of navigation bar elements (getElementsByTagName is the return element group)
 var divnum = document.getelementsbyclassname ("Eachdiv"); Gets the number of div for the navigation element for
 (var i=0;i<number.length;i++) {//number is an array, which should display its length of 5
  number[i with Number.length]. ClassName = ""; Clears the special style for all navigation bar elements
  Divnum[i].style.display = "none";//All other div is hidden
 }
 _this.classname = "L_nav1_no1"; Add a style to the current navigation bar element
 var content = document.getElementById ("l_no2_" +num);//The Div content.style.display for the current navigation bar element
 "Block"; Displays the div section for the current navigation bar element
}


HTML code:

<! DOCTYPE html>  

Effect Chart:

Debug Notes:

1. Error One:

var number = Tag.getelementsbytagname ("a"). Length;

(1) Error:

(2) Interpretation and correction:

**getelementsbytagname () is to return to the element group, if you take its length, number is just a figure, so number[i].classname = ""; **

Correct:

var number = Tag.getelementsbytagname ("a");

2. Error Two:

 for (Var i=0;i<number;i++) { 
  number[i].classname = ""; Clears the special style for all navigation bar elements
  Divnum[i].style.display = "none";//All other div is hidden
 }

The number here should be a digit, representing the number of a elements, the length of which is obtained by the error, which should read:

for (Var i=0;i<number.length;i++) {//number is an array
  number[i].classname = ""; Clears the special style for all navigation bar elements
   Divnum[i].style.display = "none";//All other div is hidden
  }

The above is the entire content of this article, I hope to help you learn.

Related Article

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.