js gets the node of C selected by Treeview selects the CheckBox item
- 2020-05-19 04:43:06
- OfStack
There are a lot of methods on the web, and they all have flaws in the first try. Finally, I found one that seemed to have less code and was satisfactory. The test result said that several functions did not exist, so I set breakpoint debugging and searched for useful fields for each property. Finally, I found it.
It is sorted as follows:
First, to get the checkbox node in treeview in javascript, you need to set some properties of the treeview node, which I added in the background code.
Get Treeview node with Input control: var tree = document. getElementById("treenameOrid").getElementsByTagName("input");
The top is checkbox, so tree selects the item with checkbox. It differs from var treeitem=document.getElementById("treenameorid"); Cannot traverse directly to get text and value;
if (tree[i].type == "checkbox" && tree[i].checked) {content}
Get the required values for each node: var s = tree[i]. nextSibling. pathname; I found out it cost me a lot of brain cells. To get a value with this property, you must set the property newNode.NavigateUrl = the required value;
Okay, now give me the complete code for an javascript:
Now, run it, see if it's the result you need, and if it's not, don't forget to set breakpoints and debug.
It is sorted as follows:
First, to get the checkbox node in treeview in javascript, you need to set some properties of the treeview node, which I added in the background code.
TreeNode newNode = new TreeNode();
newNode.Text = " showText " ;
newNode.Value =id;
newNode.NavigateUrl = id; // Can be used to in javascript Get what you need value or text value
newNode.ShowCheckBox = true; // According to checkbox
newNode.Expanded = false; // Nodes in the fold
newNode.Checked = true; //checkbox The selected
Get Treeview node with Input control: var tree = document. getElementById("treenameOrid").getElementsByTagName("input");
The top is checkbox, so tree selects the item with checkbox. It differs from var treeitem=document.getElementById("treenameorid"); Cannot traverse directly to get text and value;
if (tree[i].type == "checkbox" && tree[i].checked) {content}
Get the required values for each node: var s = tree[i]. nextSibling. pathname; I found out it cost me a lot of brain cells. To get a value with this property, you must set the property newNode.NavigateUrl = the required value;
Okay, now give me the complete code for an javascript:
var idlist;
function GeSelectedNode() {
var getAllNodes = "";
idlist = new Array(); // Instantiate 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 = Need the value of the ;
getAllNodes += s + '/';
idlist.push(s); // Adds the value to the end of the array 1 Item;
}
}
alert(tree.length);
alert(getAllNodes);
}
Now, run it, see if it's the result you need, and if it's not, don't forget to set breakpoints and debug.