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);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章