您能给我推荐一种在 ASP.NET 页面上放置倒计时器的方法吗?
现在我使用这段代码:
默认.aspx
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server">60</asp:Label>
<asp:Timer ID="Timer1" runat="server" Interval="1000"
ontick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
默认.aspx.cs
protected void Timer1_Tick(object sender, EventArgs e)
{
int seconds = int.Parse(Label1.Text);
if (seconds > 0)
Label1.Text = (seconds - 1).ToString();
else
Timer1.Enabled = false;
}
但交通费很贵。我更喜欢纯粹的客户端方法。在 ASP.NET 中可以吗?
好吧,最后我结束了
<span id="timerLabel" runat="server"></span>
<script type="text/javascript">
function countdown()
{
seconds = document.getElementById("timerLabel").innerHTML;
if (seconds > 0)
{
document.getElementById("timerLabel").innerHTML = seconds - 1;
setTimeout("countdown()", 1000);
}
}
setTimeout("countdown()", 1000);
</script>
真的很简单。就像老式的纯 HTML 和 JavaScript 一样。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)