【发布时间】:2011-04-22 17:50:05
【问题描述】:
我有一个动态构建的树视图控件。我想更改所选节点的颜色 .one 帮助我编写下面给出的脚本。并且工作正常。
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.4.2");
google.setOnLoadCallback(function() {
//change cursor to hand when user mouseover tree nodes
$(".TreeView1_0").mouseover(function() {
$(this).css('cursor', 'pointer');
});
//unbold all nodes then bold the selected node to indicate it's selected
$(".TreeView1_0").click(function() {
$(".TreeView1_0").css('font-weight', 'normal');
$(".TreeView1_0").css('color', 'black');
$(".TreeView1_0").css('background-color', 'white');
$(this).css('color', 'white');
$(this).css("background-color", "blue");
});
});
</script>
现在我想将源文件更改为存储在脚本文件夹中的 js 文件。并将选定的节点索引和值存储在隐藏字段中。我在脚本文件夹中有一个源文件 JQuery1.4.1.js。我不知道引用这个 js 文件的确切方法是什么。而且我不知道如何检索选定的节点索引和值
我更改了代码来做到这一点。整个 aspx 代码如下所示
<script type="text/javascript" src="../../Scripts/JQuery1.4.1.js"></script>
<script type="text/javascript">
//change cursor to hand when user mouseover tree nodes
$(".TreeView1_0").mouseover(function() {
$(this).css('cursor', 'pointer');
});
//unbold all nodes ,then bold the selected node to indicate it's selected ,and store selected node index and value to two hidden fields
$(".TreeView1_0").click(function() {
$(".TreeView1_0").css('font-weight', 'normal');
$(".TreeView1_0").css('color', 'black');
$(".TreeView1_0").css('background-color', 'white');
$(this).css('color', 'white');
$(this).css("background-color", "blue");
// i am not sure about the two lines of code given below
document.getElementById('hfvalue').value = $(this).value;
document.getElementById('hfindex').value =$(this).index;
$(this).css('color', 'white');
$(this).css("background-color", "blue");
});
</script>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server">
</asp:TreeView>
</div>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:HiddenField ID="hfvalue" runat="server" />
<asp:HiddenField ID="hfindex" runat="server" />
</p>
</form>
正文>
但代码不起作用。我是新手。任何建议
【问题讨论】:
标签: javascript treeview