获取treeview的CheckBox的值
functionGetCheckedBoxValues(){varcheckedBoxValues="0";varinputs=document.getElementBy...
function GetCheckedBoxValues() {
var checkedBoxValues = "0";
var inputs = document.getElementById("table1").getElementsByTagName("input");
for (var j = 0; j < inputs.length; j++) {
if (inputs[j].type == "checkbox" && inputs[j].id != "checkboxAll" && inputs[j].id != "CheckBoxListGroup_0") {
if (inputs[j].checked == true) {
checkedBoxValues += ("," + "'" + inputs[j].value + "'");
checkCount++;
}
}
}
alert(checkedBoxValues);
return checkedBoxValues;
}
<table cellpadding="10" cellspacing="0" border="0" width="100%" id="table1">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TreeView ID="TreeViewData" runat="server" ShowCheckBoxes="All"
ShowLines="True" onselectednodechanged="TreeViewData_SelectedNodeChanged">
<RootNodeStyle Font-Bold="False" Font-Size="14px" />
</asp:TreeView>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
<input type="button" value="测试" onclick="GetCheckedBoxValues()" />
怎么获取不到选中的Cehckbox的值 每次弹出来的是 0,’on‘
分不够还可以在加 展开
var checkedBoxValues = "0";
var inputs = document.getElementById("table1").getElementsByTagName("input");
for (var j = 0; j < inputs.length; j++) {
if (inputs[j].type == "checkbox" && inputs[j].id != "checkboxAll" && inputs[j].id != "CheckBoxListGroup_0") {
if (inputs[j].checked == true) {
checkedBoxValues += ("," + "'" + inputs[j].value + "'");
checkCount++;
}
}
}
alert(checkedBoxValues);
return checkedBoxValues;
}
<table cellpadding="10" cellspacing="0" border="0" width="100%" id="table1">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TreeView ID="TreeViewData" runat="server" ShowCheckBoxes="All"
ShowLines="True" onselectednodechanged="TreeViewData_SelectedNodeChanged">
<RootNodeStyle Font-Bold="False" Font-Size="14px" />
</asp:TreeView>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
<input type="button" value="测试" onclick="GetCheckedBoxValues()" />
怎么获取不到选中的Cehckbox的值 每次弹出来的是 0,’on‘
分不够还可以在加 展开
1个回答
展开全部
一定要用JS获取吗?
JS不好获取,因为TreeView 生产的input中checkbox没有value值
能不能用后台获取
private void EachTreeView( ref string values,TreeNodeCollection tn)
{
for (int i = 0; i < tn.Count; i++)
{
if (tn[i].Checked)
{
// Response.Write(tn[i].Value + "<br />");
values += tn[i].Value + ",";
}
EachTreeView(ref values,tn[i].ChildNodes);
}
}
调用
string values = "";
EachTreeView(ref values,TreeView1.Nodes);
Response.Write(values);
JS不好获取,因为TreeView 生产的input中checkbox没有value值
能不能用后台获取
private void EachTreeView( ref string values,TreeNodeCollection tn)
{
for (int i = 0; i < tn.Count; i++)
{
if (tn[i].Checked)
{
// Response.Write(tn[i].Value + "<br />");
values += tn[i].Value + ",";
}
EachTreeView(ref values,tn[i].ChildNodes);
}
}
调用
string values = "";
EachTreeView(ref values,TreeView1.Nodes);
Response.Write(values);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询