=== =方法1= ===
<script language="JavaScript"><!--//
var overDate =1//设置要倒计时的小时数 EndTimeMsg = overDate *60*60function 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 <0) window.location ="finished.aspx";
}
setInterval("show()", 1000)
// --></script></head><body><strong id="HH"></strong>时 <strong id="MM"></strong>分 <strong id="SS"></strong>秒
</body></html>
======= 在最后10秒给个提醒然后触发我的submit按钮事件!=====================
<script language="JavaScript"><!--//
var overDate =0.005//设置要倒计时的小时数 EndTimeMsg = overDate *60*60function 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) {
document.getElementById("SS").innerHTML = s
document.getElementById("OK").innerHTML =" 后将自动交卷,或者自己点击交卷。"
}
if (EndTimeMsg <0) {
document.forms[0].submit()
}
}
setInterval("show()", 1000)
// --></script></head><body>
<form action="http://dotnet.aspx.cc/">
<strong id="HH"></strong>时 <strong id="MM"></strong>分 <strong id="SS"></strong>秒<strong id="OK" style="color:red"></strong>
</form></body></html>
========方法三 aspx页面 代码====
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="OAuth.WebForm1" %>
<!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 id="Head1" 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>
================= 计时答题 ===========================
//-----------------------------计时-------------------------------//
var SysSecond;
var InterValObj;
$(document).ready(function () {
SysSecond = parseInt($("#lblTime").html()) * 60; //这里获取倒计时的起始时间
InterValObj = window.setInterval(SetRemainTime, 1000); //间隔函数,1秒执行
});
//将时间减去1秒,计算天、时、分、秒
function SetRemainTime() {
if (SysSecond > 0) {
SysSecond = SysSecond - 1;
var second = Math.floor(SysSecond % 60); // 计算秒
var minite = Math.floor((SysSecond / 60) % 60); //计算分
var hour = Math.floor((SysSecond / 3600) % 24); //计算小时
// var day = Math.floor((SysSecond / 3600) / 24); //计算天
//当时间为0时提交答案
if (second == 0 & minite == 0 & hour == 0) {
// alert("56");
var str1 = ""; //答案
//循环题号
for (var i = 1; i < $(":checkbox").length / 4; i++) {
//判断应试者有没选择
if ($("#lbl" + i).text() != "") {
str1 += i + "." + $("#lbl" + i).text() + "."; //拼接答案
} else {
// 如果没有选就用“无”代替
str1 += i + ".无.";
}
}
$.ajax({
type: "POST",
url: "Exam.aspx/GetAnswer",
data: "{'str':'" + str1 + "','str1':'" + $("#lblId").text() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function Success(data) {
// printEmployeeCars();
alert(data.d);
window.location.href = "KaoShi.aspx";
}
,
error: function (err) {
alert(err);
}
}); return false;
}
// if (minite == 5) {
// alert(");
// }
$("#lblUserTime").html(hour + ":" + minite + ":" + second);
} else {//剩余时间小于或等于0的时候,就停止间隔函数
window.clearInterval(InterValObj);
//这里可以添加倒计时时间为0后需要执行的事件
}
}