asp.net 后台调用JS函数

wayne888 2010-01-10 08:53:14
js文件如下:
var dynamicMsg = null;
function init() {
dynamicMsg = new DynamicMessage(window.document.title, "【新消息】", "【 】");
}

function begin() {
dynamicMsg.initIntervalMsg();
}

function end() {
dynamicMsg.clearIntervalMsg();
}

/**
* 处理新消息提示的操作
*/
function DynamicMessage(defaultMsg, msg, hiddenMsg) {
this.initIntervalMsg = function() {
this.intervalMsg = setInterval(function() {
if(!this.bMsg) {
window.document.title = msg + " - " + defaultMsg;
this.bMsg = true;
} else {
window.document.title = hiddenMsg + " - " + defaultMsg;
this.bMsg = false;
}
},
1000
);
};

this.clearIntervalMsg = function() {
if(this.intervalMsg != null) {
clearInterval(this.intervalMsg);
window.document.title = defaultMsg;
this.bMsg = false;
}
};
}

aspx文件如下:
<body onload="init();">

<form id="form1" runat="server">
<div>
<center>
<input type="button" value="begin" onclick="begin();"/>
<input type="button" value="end" onclick="end();"/>
<br />
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br/>


</center>
</div>
</form>
</body>

aspx.cs文件如下:
protected void Button1_Click(object sender, EventArgs e)
{
//Page.RegisterClientScriptBlock("", "<script language='javascript'>begin()</script>");
this.ClientScript.RegisterStartupScript(typeof(string), "js", "begin();", true);
}

调试过程中,input按钮没有问题。。。button按钮无法完成功能,提示“错误: 'dynamicMsg' 为空或不是对象”
哪位高手知道啊?
...全文
161 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hangang7403 2010-01-11
  • 打赏
  • 举报
回复
up
antony1029 2010-01-10
  • 打赏
  • 举报
回复
顶!
wayne888 2010-01-10
  • 打赏
  • 举报
回复
各位大侠。我只是想用两个button控制标题栏消息的闪动和停止
xray2005 2010-01-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 cuike519 的回复:]
声明的类型在使用它之后。。。

这个是比较常遇到的问题,JS是解释型的,所以前后位置很重要。
[/Quote]

同意
cuike519 2010-01-10
  • 打赏
  • 举报
回复
声明的类型在使用它之后。。。

这个是比较常遇到的问题,JS是解释型的,所以前后位置很重要。
wayne888 2010-01-10
  • 打赏
  • 举报
回复
。。。有出问题了,麻烦继续讨论下。。。。就是上面的问题
wiki14 2010-01-10
  • 打赏
  • 举报
回复
接分~
恭喜楼主,贺喜楼主。- -
wuyq11 2010-01-10
  • 打赏
  • 举报
回复
解决就好
koukoujiayi 2010-01-10
  • 打赏
  • 举报
回复
那我就接分了!!谢楼主
wayne888 2010-01-10
  • 打赏
  • 举报
回复
谢谢正在思考的朋友,解决了。。。。

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧