JQuery implements clicking TreeView text to expand/collapse subnodes, and jquerytreeview
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:
<Script type = "text/javascript"> $ (). ready (function () {$ ("img1_src1_1_ TV _noexpend.jpg]"). each (function () // filter out all parent node {// ctl00_body _ menuTreet4i // the id of the parent node is as follows: 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 ); // 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>