TreeView无刷新获取text及value实现代码
程序员文章站
2024-02-29 20:16:22
前台代码:复制代码 代码如下:
前台代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
<title></title>
<style type="text/css">
#middle{ top:0; left:0;background-color:#fff; position:absolute; z-index:2; filter:alpha(opacity=60); display:none;}
#showtree{ width:300px; height:200px; position:fixed; z-index:2; display:none; border:1px solid red;}
</style>
<script type="text/javascript">
function showdiv() {
var txt = document.getelementbyid("txt");
txt.blur();
var divmid = document.getelementbyid("middle");
divmid.style.display = "block";
divmid.style.width = "100%";
divmid.style.height = "100%";
var divshow = document.getelementbyid("showtree");
divshow.style.display = "block";
divshow.style.left = txt.offsetleft;
divshow.style.top = txt.offsettop;
return false;
}
function closediv() {
var divmid = document.getelementbyid("middle");
divmid.style.display = "none";
var divshow = document.getelementbyid("showtree");
divshow.style.display = "none";
return false;
}
function treeviewclick() {
if (event.srcelement.innertext == "" || event.srcelement.length <= 0 || event.srcelement.nameprop == undefined) {
return true;
}
var id = event.srcelement.id;
var a = document.getelementbyid(id);
var href = a.href;
var index = href.indexof("#");
var retstr = href.substr(index + 1);
//
var ret = a.innertext;
if (ret != "") {
document.getelementbyid("txt").value = ret;
document.getelementbyid("textbox2").value = retstr;
document.getelementbyid("hiddenfield1").value = retstr;
}
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:hiddenfield id="hiddenfield1" runat="server" />
<asp:button id="button1" runat="server" text="显示value" onclick="button1_click" />
<br />
<asp:textbox id="textbox1" runat="server"></asp:textbox>
<br />
text:<asp:textbox id="txt" runat="server" onfocus="return showdiv()"></asp:textbox>
<br />
value:
<asp:textbox id="textbox2" runat="server"></asp:textbox>
</div>
<div id="middle"></div>
<div id="showtree">
<br />
<br />
<input type="button" value="close" onclick="return closediv()" />
<asp:treeview id="treeview1" runat="server">
<nodes>
<asp:treenode text="a" value="0" navigateurl="#0">
<asp:treenode text="a1" value="00" navigateurl="#00">
<asp:treenode text="a11" value="000" navigateurl="#000"></asp:treenode>
<asp:treenode text="a12" value="001" navigateurl="#001"></asp:treenode>
</asp:treenode>
<asp:treenode text="a2" value="01" navigateurl="#01"></asp:treenode>
<asp:treenode text="a3" value="02" navigateurl="#02"></asp:treenode>
</asp:treenode>
<asp:treenode text="b" value="1" navigateurl="#1">
<asp:treenode text="b1" value="10" navigateurl="#10"></asp:treenode>
<asp:treenode text="b2" value="11" navigateurl="#11"></asp:treenode>
<asp:treenode text="b3" value="12" navigateurl="#12"></asp:treenode>
</asp:treenode>
</nodes>
</asp:treeview>
</div>
</form>
</body>
</html>
后台代码:
public partial class newpage_default2 : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
this.treeview1.attributes.add("onclick", "return treeviewclick()");//增加特性,实现无自动回传
}
protected void button1_click(object sender, eventargs e)
{
this.textbox1.text = this.hiddenfield1.value;
}
}
复制代码 代码如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
<title></title>
<style type="text/css">
#middle{ top:0; left:0;background-color:#fff; position:absolute; z-index:2; filter:alpha(opacity=60); display:none;}
#showtree{ width:300px; height:200px; position:fixed; z-index:2; display:none; border:1px solid red;}
</style>
<script type="text/javascript">
function showdiv() {
var txt = document.getelementbyid("txt");
txt.blur();
var divmid = document.getelementbyid("middle");
divmid.style.display = "block";
divmid.style.width = "100%";
divmid.style.height = "100%";
var divshow = document.getelementbyid("showtree");
divshow.style.display = "block";
divshow.style.left = txt.offsetleft;
divshow.style.top = txt.offsettop;
return false;
}
function closediv() {
var divmid = document.getelementbyid("middle");
divmid.style.display = "none";
var divshow = document.getelementbyid("showtree");
divshow.style.display = "none";
return false;
}
function treeviewclick() {
if (event.srcelement.innertext == "" || event.srcelement.length <= 0 || event.srcelement.nameprop == undefined) {
return true;
}
var id = event.srcelement.id;
var a = document.getelementbyid(id);
var href = a.href;
var index = href.indexof("#");
var retstr = href.substr(index + 1);
//
var ret = a.innertext;
if (ret != "") {
document.getelementbyid("txt").value = ret;
document.getelementbyid("textbox2").value = retstr;
document.getelementbyid("hiddenfield1").value = retstr;
}
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:hiddenfield id="hiddenfield1" runat="server" />
<asp:button id="button1" runat="server" text="显示value" onclick="button1_click" />
<br />
<asp:textbox id="textbox1" runat="server"></asp:textbox>
<br />
text:<asp:textbox id="txt" runat="server" onfocus="return showdiv()"></asp:textbox>
<br />
value:
<asp:textbox id="textbox2" runat="server"></asp:textbox>
</div>
<div id="middle"></div>
<div id="showtree">
<br />
<br />
<input type="button" value="close" onclick="return closediv()" />
<asp:treeview id="treeview1" runat="server">
<nodes>
<asp:treenode text="a" value="0" navigateurl="#0">
<asp:treenode text="a1" value="00" navigateurl="#00">
<asp:treenode text="a11" value="000" navigateurl="#000"></asp:treenode>
<asp:treenode text="a12" value="001" navigateurl="#001"></asp:treenode>
</asp:treenode>
<asp:treenode text="a2" value="01" navigateurl="#01"></asp:treenode>
<asp:treenode text="a3" value="02" navigateurl="#02"></asp:treenode>
</asp:treenode>
<asp:treenode text="b" value="1" navigateurl="#1">
<asp:treenode text="b1" value="10" navigateurl="#10"></asp:treenode>
<asp:treenode text="b2" value="11" navigateurl="#11"></asp:treenode>
<asp:treenode text="b3" value="12" navigateurl="#12"></asp:treenode>
</asp:treenode>
</nodes>
</asp:treeview>
</div>
</form>
</body>
</html>
后台代码:
复制代码 代码如下:
public partial class newpage_default2 : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
this.treeview1.attributes.add("onclick", "return treeviewclick()");//增加特性,实现无自动回传
}
protected void button1_click(object sender, eventargs e)
{
this.textbox1.text = this.hiddenfield1.value;
}
}
推荐阅读
-
TreeView无刷新获取text及value实现代码
-
TreeView无刷新获取text及value实现代码
-
ASP中SELECT下拉菜单同时获取VALUE和TEXT值的实现代码
-
javascript实现TreeView 无刷新展开的实例代码_javascript技巧
-
JS获取下拉列表所选中的TEXT和Value的实现代码_javascript技巧
-
js获取RadioButtonList的Value/Text及选中值等信息实现代码_javascript技巧
-
js获取RadioButtonList的Value/Text及选中值等信息实现代码_javascript技巧
-
JS获取下拉列表所选中的TEXT和Value的实现代码_javascript技巧
-
javascript实现TreeView 无刷新展开的实例代码_javascript技巧
-
ASP中SELECT下拉菜单同时获取VALUE和TEXT值的实现代码