JavaScript implements code folding function _javascript Skills

Source: Internet
Author: User

First, define a JavaScript function , as follows:

function Puckermenu (level) {
var levellength = (' row ' + level). Length;
var toDo = ' 0 ';
for (var icount = 0; icount < document.all.length; icount++) {
if (document.all[icount].id.indexof (' row ' + level) > 1 && (Document.all[icount].id.length > Levellength) {
if document.all (' level ' + level). Src.index Of (' Minus.gif ') >-1) {
Document.all[icount].style.display = ' none ';
ToDo = ' 1 ';
} else {
Document.all[icount].style.display = ' block ';
ToDo = ' 0 ';
}}}  if (ToDo = = ' 1 ') {
document.all (' level ' + level). src = ' images/plus.gif ';
 } else {
document.all (' level ' + level). src = ' images/minus.gif ';
 }
}

Second, then on the Web page to define one div and one ul , note div to include a id level start image and an onclick event, ul id to include row , by default, is expanded, if you need to default to closed, You want to ul join in thestyle="display:none"

Examples are as follows:

<body>
<divstyle= "Cursor:hand"
onclick= "Puckermenu (' 1 ');" >public class dataaccess</div>
<ulid=row1>
<li> private string connstring;
<divstyle= "Cursor:hand"
onclick= "Puckermenu (' 2 ');" >protected dbconnection openconnection () </div>
< Ulid=row2style= "Display:none" >{...} </ul>
<li>
other
</ul>
</body>

Summarize

The above is the entire content of this article, I hope to be able to help people in need. If you have questions, you can leave a message for discussion.

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.