我在 asp:content 中有一个 div :
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="slidebar" style="display:none;" >There are some pending approvals.Please approve by the 25th of this month
<a href="#" id="slink" style="margin-left:10px;" onclick="fade('slidebar');">Click here to close <sup style="font:caption;color:#373636;">X</sup></a>
</div>
<script language="javascript" type="text/javascript">
function showbanner()
{
document.getElementById("slidebar").style.visibility="visible";
}
</script>
<\asp:content>
以及背后的代码:
ClientScript.RegisterClientScriptBlock(Page.GetType(), "displaybanner", "return showbanner();", true);
我无法从后面的代码中调用函数 showbanner,即使我直接使用 registerclientscript 调用 showbanner 中的语句...它也不会被调用。
请帮忙
最佳答案
属性visibility
和display
不一样,改js函数为:
function showbanner()
{
document.getElementById("slidebar").style.display="block";
}
同时将您的代码更改为
ClientScript.RegisterStartupScript(Page.GetType(), "displaybanner", "showbanner();", true);
因此脚本会在页面加载后执行,否则它将找不到该元素。
关于C# asp.net 调用 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5185521/