日期:2014-05-20  浏览次数:20689 次

倒计时时间到了之后没有弹出框提示,也没有触发Button按钮,
C# code

 <script language="JavaScript">
<!--        //
        var overDate = 1 //小时
        //        EndTimeMsg = overDate * 60 * 60
        EndTimeMsg = overDate 
        function show() {
            h = Math.floor(EndTimeMsg / 60 / 60);
            m = Math.floor((EndTimeMsg - h * 60 * 60) / 60)
            s = Math.floor((EndTimeMsg - h * 60 * 60 - m * 60))
            document.getElementById("RemainH").innerHTML = h
            document.getElementById("RemainM").innerHTML = m
            document.getElementById("RemainS").innerHTML = s
            EndTimeMsg--;
            //            if (EndTimeMsg < 0) window.location = "finished.aspx";
            if (EndTimeMsg < 10) {
                document.getElementById("SS").innerHTML = s + " 后交卷"
            }
            if (EndTimeMsg < 0) {
                document.getElementById("Button1").click()
            }
        }
        setInterval("show()", 1000)
// -->
</script>




------解决方案--------------------
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("你已经交卷。");
//代码进行处理,跳转到
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var overDate = 0.004 //设置要倒计时的小时数
EndTimeMsg = overDate * 60 * 60
function show() {
h = Math.floor(EndTimeMsg / 60 / 60);
m = Math.floor((EndTimeMsg - h * 60 * 60) / 60)
s = Math.floor((EndTimeMsg - h * 60 * 60 - m * 60))
document.getElementById("HH").innerHTML = h
document.getElementById("MM").innerHTML = m
document.getElementById("SS").innerHTML = s
EndTimeMsg--;
if (EndTimeMsg <= 10 && EndTimeMsg > 9) {
alert(s + " 后将自动交卷");
document.getElementById("SS").innerHTML = s
document.getElementById("OK").innerHTML = " 后将自动交卷"
}
if (EndTimeMsg < 0) {
document.getElementById('<%=Button1.ClientID %>').click();
}
}
setInterval("show()", 1000)
</script>
</head>
<body>
<form id="form1" runat="server">
<div><strong id="HH"></strong>时 <strong id="MM"></strong>分 <strong id="SS"></strong>
秒<strong id="OK" style="color: red"></strong> </div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="交卷" />
</form>
</body>
</html>