获得TreeView CheckBox里选中项的值,对JSDOM控制还不是很熟,感觉不太容易。试了很多次终于成功了。
代码如下
<body>
<form id="form1"
runat="server">
<div>
<asp:TreeView
ID="tvDepartment"
runat="server">
</asp:TreeView>
<input
type="button" value="获得" onclick="getEle()"
/>
<br
/>
<br
/>
<br
/>
</div>
</form>
</body>
</html>
<script
language="javascript" type="text/javascript">
function
getEle() {
var tree =
document.getElementById("tvDepartment").getElementsByTagName("INPUT");
for (var i = 0; i < tree.length; i++)
{
if
(tree[i].type == "checkbox" && tree[i].checked)
{
alert(tree[i].nextSibling.firstChild.nodeValue);
}
}
}
</script>