JS get TreeView selected Node (C # Check checkbox entry) _ Practical Tips

Source: Internet
Author: User
Methods there are a lot of online, try it all flawed. Finally found a less code, more pleasing to the eye, the test results reported that there are several functions do not exist, so set breakpoints debugging, each property to find useful fields, finally found.
is sorted as follows
First, to get the node with the checkbox in the TreeView in JavaScript, you need to set some of the properties of the TreeView node, which I added in the background code.
Copy Code code as follows:

TreeNode NewNode = new TreeNode ();
Newnode.text = "Showtext";
Newnode.value =id;
Newnode.navigateurl = ID; Can be used to get the desired value or text value in JavaScript
Newnode.showcheckbox = true; Show checkbox
newnode.expanded = false; Node collapse
Newnode.checked = true; CheckBox selected

Gets the node for the TreeView with the input control: var tree = document.getElementById ("Treenameorid"). getElementsByTagName ("input");
The top set is a checkbox, so the tree picks the item with the checkbox. It is different from Var Treeitem=document.getelementbyid ("Treenameorid") and can not be traversed to get text and value directly;
Gets the node selected by the checkbox in the TreeView, usually as a criterion: if (Tree[i].type = = "checkbox" && tree[i].checked) {content}
Get the values that each node needs: var s = tree[i].nextsibling.pathname; Found this cost me a lot of brain cells. To get a value with this property, you must set the property Newnode.navigateurl = required value;
Okay, now give me a complete code for JavaScript.
Copy Code code as follows:

var idlist;
function Geselectednode () {
var getallnodes = "";
Idlist = new Array (); Instantiating an array
var tree = document.getElementById ("Treenameorid"). getElementsByTagName ("input");
for (var i = 0; i < tree.length; i++) {
if (Tree[i].type = = "checkbox" && tree[i].checked) {
var s = tree[i].nextsibling.pathname; To get a value with this property, you must set the property Newnode.navigateurl = required value;
Getallnodes + = s + '/';
Idlist.push (s); Adds a value into the last item of the array;
}
}
alert (tree.length);
alert (getallnodes);
}

Now, run up and see if you need the results, if not, don't forget to set the breakpoint debugging Oh.
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.