JavaScript倒计时返回页面效果

HTML部分:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function sessionTimeout()
{
var label=document.getElementById("lblTime");
var seconds=parseInt(label.value);
seconds=seconds-1;
label.value=seconds.toString();
if(seconds==0)
{
alert("您已超时");
window.location.href="login.aspx";//转到登陆页
clearInterval(sessionTimeout);
}
}
window.setInterval(sessionTimeout,1000);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>剩余秒数:
<input ID="lblTime" name="lblTime" runat="server" type="text" style="border:0px;width:20px;" />
<asp:Button ID="Button1" runat="server" Text="操作" /></div>
</form>
</body>
</html>


.CS文件部分:
protected void Page_Load(object sender, EventArgs e)
{
Session["time"] = System.DateTime.Now.ToString();
Session.Timeout = 1;
lblTime.Value = Convert.ToString(Convert.ToInt32(Session.Timeout) * 60);

posted on 2009-07-12 00:52  晴天1848  阅读(657)  评论(0编辑  收藏  举报