Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 脚本为外部时的getElementByID_Javascript_Asp.net - Fatal编程技术网

Javascript 脚本为外部时的getElementByID

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

我试图访问外部脚本中的asp:面板,使其不可见,但它似乎不起作用。当脚本在.aspx文件中时,它工作正常。有什么建议吗

在.aspx文件中

  <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";
}