Javascript 脚本为外部时的getElementByID
我试图访问外部脚本中的asp:面板,使其不可见,但它似乎不起作用。当脚本在.aspx文件中时,它工作正常。有什么建议吗 在.aspx文件中Javascript 脚本为外部时的getElementByID,javascript,asp.net,Javascript,Asp.net,我试图访问外部脚本中的asp:面板,使其不可见,但它似乎不起作用。当脚本在.aspx文件中时,它工作正常。有什么建议吗 在.aspx文件中 <script src="App_Themes/custom.js"></script> <asp:Button ID="descriptionButton" Text="Description" runat="server" OnClientClick="descButton(); return false;" /&g
<script src="App_Themes/custom.js"></script>
<asp:Button ID="descriptionButton" Text="Description" runat="server" OnClientClick="descButton(); return false;" />
<asp:Panel ID="desciptionPanel" runat="server">
///random stuff
<asp:panel>
///随机的东西
在custom.js文件中
function descButton() {
var desc = document.getElementById('<%=desciptionPanel.ClientID%>');
desc.style.visibility = "visible";
desc.style.height = "800px";
}
功能描述按钮(){
var desc=document.getElementById(“”);
desc.style.visibility=“可见”;
desc.style.height=“800px”;
}
提前谢谢把它一分为二
首先,在服务器的aspx中,保留ID以便以后可以重用
<script>
window.panelID = '<%= whatever.ClientID %>';
</script>
在函数中使用参数
OnClientClick="descButton('<%=desciptionPanel.ClientID%>');
-这是asp.net指令,不是js指令,它只能在aspx文件中工作谢谢!完美地工作
OnClientClick="descButton('<%=desciptionPanel.ClientID%>');
function descButton(id) {
var desc = document.getElementById(id);
desc.style.visibility = "visible";
desc.style.height = "800px";
}