我用VS2008编的,当我点击表的列时提示document.getelementid() 为空或不是对象,希望高手指点。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TubePartLeft.aspx.cs" Inherits="TubePartManage_TubePartLeft" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body style="padding: 0px; margin: 0px">
<form id="form1" runat="server">
<div>
<table style="width: 100%;" cellpadding="0" cellspacing="0" id="TubeTable">
<tr>
<td style="background-color: #AACDFF; color: #FFFFFF; font-weight: bold; cursor:hand;"
align="center" height="35px" valign="middle" id="tbTubePart" onclick="changePartcolor()">
目录一
</td>
<td style="background-color: #0000FF; font-weight: bold; color: #FFFFFF; cursor:hand;"
align="center" height="35px" valign="middle" id="tdTubeSample" onclick="changeSamplecolor()">
目录二
</td>
</tr>
<tr>
<td style="background-color: #AACDFF; overflow: scroll;"
colspan="2" height="100%">
<asp:MultiView ID="TubeMultiView" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<asp:TreeView ID="tvwTubePart" runat="server" Font-Size="Small"
ShowLines="True">
</asp:TreeView>
</asp:View>
<asp:View ID="View2" runat="server">
<asp:TreeView ID="tvwTubeSample" runat="server" Font- Size="Small">
</asp:TreeView>
</asp:View>
</asp:MultiView>
</td>
</tr>
</table>
</div>
</form>
</body>
<script type="text/javascript">
function changePartcolor()
{
tbTubePart.style.backgroundColor="#AACDFF";
tdTubeSample.style.backgroundColor="#0000FF";
document.getElementById("TubeMultiView").ActiveViewIndex = "0";
}
function changeSamplecolor()
{
tbTubePart.style.backgroundColor="#0000FF";
tdTubeSample.style.backgroundColor="#AACDFF";
document.getElementById("TubeMultiView").ActiveViewIndex = "1";
}
</script>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TubePartLeft.aspx.cs" Inherits="TubePartManage_TubePartLeft" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body style="padding: 0px; margin: 0px">
<form id="form1" runat="server">
<div>
<table style="width: 100%;" cellpadding="0" cellspacing="0" id="TubeTable">
<tr>
<td style="background-color: #AACDFF; color: #FFFFFF; font-weight: bold; cursor:hand;"
align="center" height="35px" valign="middle" id="tbTubePart" onclick="changePartcolor()">
目录一
</td>
<td style="background-color: #0000FF; font-weight: bold; color: #FFFFFF; cursor:hand;"
align="center" height="35px" valign="middle" id="tdTubeSample" onclick="changeSamplecolor()">
目录二
</td>
</tr>
<tr>
<td style="background-color: #AACDFF; overflow: scroll;"
colspan="2" height="100%">
<asp:MultiView ID="TubeMultiView" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<asp:TreeView ID="tvwTubePart" runat="server" Font-Size="Small"
ShowLines="True">
</asp:TreeView>
</asp:View>
<asp:View ID="View2" runat="server">
<asp:TreeView ID="tvwTubeSample" runat="server" Font- Size="Small">
</asp:TreeView>
</asp:View>
</asp:MultiView>
</td>
</tr>
</table>
</div>
</form>
</body>
<script type="text/javascript">
function changePartcolor()
{
tbTubePart.style.backgroundColor="#AACDFF";
tdTubeSample.style.backgroundColor="#0000FF";
document.getElementById("TubeMultiView").ActiveViewIndex = "0";
}
function changeSamplecolor()
{
tbTubePart.style.backgroundColor="#0000FF";
tdTubeSample.style.backgroundColor="#AACDFF";
document.getElementById("TubeMultiView").ActiveViewIndex = "1";
}
</script>
</html>
{
tbTubePart.style.backgroundColor="#AACDFF";
tdTubeSample.style.backgroundColor="#0000FF";
document.getElementById("<%=TubeMultiView.ClientID%>").ActiveViewIndex = "0";
}
function changeSamplecolor()
{
tbTubePart.style.backgroundColor="#0000FF";
tdTubeSample.style.backgroundColor="#AACDFF";
document.getElementById("<%=TubeMultiView.ClientID%>").ActiveViewIndex = "1";
}试试看
{
tbTubePart.style.backgroundColor="#AACDFF";
tdTubeSample.style.backgroundColor="#0000FF";
document.getElementById("TubeMultiView").ActiveViewIndex = "0";
}
function changeSamplecolor()
{
tbTubePart.style.backgroundColor="#0000FF";
tdTubeSample.style.backgroundColor="#AACDFF";
document.getElementById("TubeMultiView").ActiveViewIndex = "1";
}红色的是哪来的?
<td style="background-color: #AACDFF; color: #FFFFFF; font-weight: bold; cursor:hand;"
align="center" height="35px" valign="middle" id="tbTubePart" onclick="changePartcolor()">
目录一
</td>
<td style="background-color: #0000FF; font-weight: bold; color: #FFFFFF; cursor:hand;"
align="center" height="35px" valign="middle" id="tdTubeSample" onclick="changeSamplecolor()">
目录二
</td>
{
document.getElementById("tbTubePart").style.backgroundColor="#AACDFF";
document.getElementById("tdTubeSample").style.backgroundColor="#0000FF";
document.getElementById("TubeMultiView").ActiveViewIndex = "0";
}
function changeSamplecolor()
{
document.getElementById("tbTubePart").style.backgroundColor="#0000FF";
document.getElementById("tdTubeSample").style.backgroundColor="#AACDFF";
document.getElementById("TubeMultiView").ActiveViewIndex = "1";
}
你最好打开html页面查看源代码,看看你要获得元素的客户端真正的ID是什么?
tdTubeSample.style.backgroundColor="#0000FF";
这部分代码没有问题,问题出在document.getElementById("TubeMultiView").ActiveViewIndex
你这是服务器端控件........ 所以客户端的JS取不到。改成:
document.getElementById("<%=TubeMultiView.ClientID%>").ActiveViewIndex