Jquery implements clicking the TreeView text parent node to expand/collapse the child node

Source: Internet
Author: User

I used to release a free account. Now, let's move it here.
A registered user has been busy for a while and has not written an article yet. Suddenly, it takes some time to record and summarize some things. Okay, it starts from here.

Today, when the customer proposes to click the parent node of the menu (implemented by TreeView), expand the node. I thought this should be a very common feature. I specifically Googled it and found that most of the functions are implemented by js rather than JavaScript. I have some trouble writing JavaScript implementations. Just write it by yourself, it should be difficult.

First, let's execute the '+' event on the left when clicking the text, and view the source code. The event of '+' is:
Javascript: TreeView_ToggleNode (ctl00_body _ menuTree_Data, 0, document. getElementById ('ctl00 _ body _ menuTreen0 '), '', document. getElementById ('ctl00 _ body _ menuTreen0Nodes '))
OK. The next step is to filter out all the parent nodes and process the events. The complete code is as follows:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (). Ready (function ()
{
$ ("Img1_src1_1_ TV _noexpend.jpg]"). each (function () // filter all parent nodes
{
// Ctl00_body _ menuTreet4i // The parent node id is like this rule: ctl00_body _ menuTreet and id plus I
Var id = $ (this ). parent (). attr ("id "). replace ("ctl00_body _ menuTreet ",""). replace ("I ","");
Var nId = 'ctl00 _ body _ menuTreen '+ id;
BindExpandJs ($ ("# ctl00_body _ menuTreet" + id + "I"), nId); // bind an event to the 'Folder 'image
BindExpandJs ($ ("# ctl00_body _ menuTreet" + id), nId); // bind an event to the 'text node });
});
Function BindExpandJs (obj, nId)
{
$ (Obj)
. Css ("cursor", "pointer ")
. RemoveAttr ("href ")
. Click (function ()
{
TreeView_ToggleNode (ctl00_body _ menuTree_Data, 0, document. getElementById (nId), '', document. getElementById (nId + 'nodes '));
});
}
</Script>

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.