Use XSLT to easily fold the navigation bar tree (4)

Source: Internet
Author: User
Expansion and collapse are actually displaying or not displaying display: noneorblock. it is different from visible and invisible (visibleorinvisible). The former is not reserved on the page. The toggle function has two functions. to change the Hidden attribute of TR, expand and collapse the function. display: none or block is displayed or not displayed) there is a difference. the former does not reserve space on the page. The toggle function has two functions: change the Hidden attribute of TR to display the Hidden attribute, change the src attribute of IMG, and change the image.

Toggle. js

Function toggle (id)
{
Var thisRow = document. all. item (id );
If (thisRow)
{
If (thisRow. getAttribute ('expanded') = 'yes ')
{
ThisRow. setAttribute ('expanded', 'no ');
ThisRow. children (0). children (0). children (0). src = 'Images/bs.gif ';

Var allRows = document. all. tags ('tr ');
For (var I = 1; I <allRows. length; I)
{
Var row = allRows [I];
If (row. getAttribute ('ancestorid') = id)
{
If (row. getAttribute ('expanded') = 'yes '){
Toggle (row. getAttribute ('id '));
}
Row. className = 'Navigator-Den ';
}
}
ThisRow. className = 'Navigator ';
}
Else
{
ThisRow. setAttribute ('expanded', 'yes ');
ThisRow. children (0). children (0). children (0). src = 'Images/bo.gif ';

Var allRows = document. all. tags ('tr ');
Var depth = parseInt (thisRow. getAttribute ('depth '));
For (var I = 1; I <allRows. length; I)
{
Var row = allRows [I];
If (row. getAttribute ('ancestorid') = id &&
ParseInt (row. getAttribute ('depth ') = Depth 1)
{
Row. className = 'Navigator ';
}
}
}
}
}

This ends.

It is true that the effectiveness of this TOC is still the most basic. for example, I have not synchronized content and directories, and some of them can be corrected, so that the xml and xsl files can be further reduced. However, this is sufficient for general users.
I sincerely hope that this article will inspire and help you, and make TOC more cool, faster, more convenient, and more effective in the future.

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.