本文介绍了C#asp.net的JavaScript调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有ASP里面的div:内容:
I have a div inside asp:content :
<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>
和背后的code:
ClientScript.RegisterClientScriptBlock(Page.GetType(), "displaybanner", "return showbanner();", true);
我不能把从后面甚至当我直接打电话registerclientscript里面showbanner的声明......它不被调用的code函数showbanner。
I cannot call the function showbanner from the code behind and even when I directly call the statement inside showbanner with registerclientscript ...it doesnt get called .
请帮忙
推荐答案
属性能见度
和显示
不同样,改变js函数为:
The properties visibility
and display
are not the same, change the js function to:
function showbanner()
{
document.getElementById("slidebar").style.display="block";
}
也改变你的code后面
also change your code behind to
ClientScript.RegisterStartupScript(Page.GetType(), "displaybanner", "showbanner();", true);
所以执行脚本的页面加载了,否则将找不到元素之后。
so the script executes after the page has load or else it won't find the element.
这篇关于C#asp.net的JavaScript调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!