<script type="text/javascript">
window.onload = function(){
if(window.name == "" || window.name == 0)
window.name = $("Label6").innerHTML;
}
function countDown(){
var hh = Math.floor(window.name / 3600);
var mm = Math.floor((window.name % 3600) / 60);
var ss = window.name % 3600 % 60;
$("Label6").innerHTML = add_zero(hh) + ":" +add_zero(mm) + ":" +add_zero(ss);
if(window.name > 0){
if(window.name < 3)
$("Label6").style.color = "#ff3300";
setTimeout("countDown()",1000);
window.name--;
}
else
{
alert("时间到,系统将自动交卷!");
$("Button1").click();
}
}
function add_zero(temp){
if(temp<10) return "0" + temp;
else return temp;
}
setTimeout("countDown()",1000);前台<asp:Button ID="Button1" runat="server" Height="22px" Width="50px" Text="交 卷" onclick="Button1_Click" /> protected bool readQuestions()
{
DataSet ds = new DataSet();
string sqlStr = "select * from exam_tb where ID=" + Request.QueryString["ID"].ToString();
SqlDataAdapter ad = new SqlDataAdapter(sqlStr, conn);
try
{
conn.Open();
ad.Fill(ds, "exam");
conn.Close();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>alert(\"读取考试信息出错!\");</script>");
return false;
}
finally { conn.Close(); } if (ds.Tables["exam"].Rows[0]["考试科目"].ToString() == "英语考试")
sqlStr = "select * from fxq_exam where 考试号=" + Request.QueryString["ID"].ToString() + " and 学生证号=" + Session["ID"].ToString();
else if(ds.Tables["exam"].Rows[0]["考试科目"].ToString() == "数学考试")
sqlStr = "select * from hl_exam where 考试号=" + Request.QueryString["ID"].ToString() + " and 学生证号=" + Session["ID"].ToString();
else
sqlStr = "select * from fg_exam where 考试号=" + Request.QueryString["ID"].ToString() + " and 学生证号=" + Session["ID"].ToString();
SqlCommand cmd = new SqlCommand(sqlStr, conn);
try
{
conn.Open();
SqlDataReader read = cmd.ExecuteReader();
if (read.Read())
{
conn.Close();
ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>alert(\"您已进行过考试!\");document.location.href='announcement.aspx';</script>");
return false;
}
conn.Close();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>alert(\"读取考试信息出错!\");</script>");
return false;
}
finally { conn.Close(); } Label1.Text = ds.Tables["exam"].Rows[0]["ID"].ToString();
Label2.Text = ds.Tables["exam"].Rows[0]["考试科目"].ToString();
Label3.Text = ds.Tables["exam"].Rows[0]["考试名称"].ToString();
Label4.Text = Session["ID"].ToString();
Label5.Text = Session["uname"].ToString();
Label6.Text = (Convert.ToInt32(ds.Tables["exam"].Rows[0]["时间"])*60).ToString();时间:Label6显示为NaN:NaN:NaN?怎么解决啊?不知道那个地方写错了!
window.onload = function(){
if(window.name == "" || window.name == 0)
window.name = $("Label6").innerHTML;
}
function countDown(){
var hh = Math.floor(window.name / 3600);
var mm = Math.floor((window.name % 3600) / 60);
var ss = window.name % 3600 % 60;
$("Label6").innerHTML = add_zero(hh) + ":" +add_zero(mm) + ":" +add_zero(ss);
if(window.name > 0){
if(window.name < 3)
$("Label6").style.color = "#ff3300";
setTimeout("countDown()",1000);
window.name--;
}
else
{
alert("时间到,系统将自动交卷!");
$("Button1").click();
}
}
function add_zero(temp){
if(temp<10) return "0" + temp;
else return temp;
}
setTimeout("countDown()",1000);前台<asp:Button ID="Button1" runat="server" Height="22px" Width="50px" Text="交 卷" onclick="Button1_Click" /> protected bool readQuestions()
{
DataSet ds = new DataSet();
string sqlStr = "select * from exam_tb where ID=" + Request.QueryString["ID"].ToString();
SqlDataAdapter ad = new SqlDataAdapter(sqlStr, conn);
try
{
conn.Open();
ad.Fill(ds, "exam");
conn.Close();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>alert(\"读取考试信息出错!\");</script>");
return false;
}
finally { conn.Close(); } if (ds.Tables["exam"].Rows[0]["考试科目"].ToString() == "英语考试")
sqlStr = "select * from fxq_exam where 考试号=" + Request.QueryString["ID"].ToString() + " and 学生证号=" + Session["ID"].ToString();
else if(ds.Tables["exam"].Rows[0]["考试科目"].ToString() == "数学考试")
sqlStr = "select * from hl_exam where 考试号=" + Request.QueryString["ID"].ToString() + " and 学生证号=" + Session["ID"].ToString();
else
sqlStr = "select * from fg_exam where 考试号=" + Request.QueryString["ID"].ToString() + " and 学生证号=" + Session["ID"].ToString();
SqlCommand cmd = new SqlCommand(sqlStr, conn);
try
{
conn.Open();
SqlDataReader read = cmd.ExecuteReader();
if (read.Read())
{
conn.Close();
ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>alert(\"您已进行过考试!\");document.location.href='announcement.aspx';</script>");
return false;
}
conn.Close();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>alert(\"读取考试信息出错!\");</script>");
return false;
}
finally { conn.Close(); } Label1.Text = ds.Tables["exam"].Rows[0]["ID"].ToString();
Label2.Text = ds.Tables["exam"].Rows[0]["考试科目"].ToString();
Label3.Text = ds.Tables["exam"].Rows[0]["考试名称"].ToString();
Label4.Text = Session["ID"].ToString();
Label5.Text = Session["uname"].ToString();
Label6.Text = (Convert.ToInt32(ds.Tables["exam"].Rows[0]["时间"])*60).ToString();时间:Label6显示为NaN:NaN:NaN?怎么解决啊?不知道那个地方写错了!
var hh = Math.floor(window.name / 3600);
这个地方出错的~
window.name等于啥
var ss = window.name % 3600 % 60;
值
var endTime; //后台用TimeSpan读取的时间差
var h=9;
function showEndTime()
{
var endDay=parseInt(parseInt(endTime)/(3600*24));
var endHour=parseInt(parseInt(endTime)%(3600*24)/3600);
var endMinutes=parseInt(parseInt(endTime%3600)/60);
var endSeconds=parseInt(parseInt(endTime)%60);
var showTime=endDay+"天"+endHour+"时"+endMinutes+"分"+endSeconds+"."+h+"秒";
$("#info").find("#divLength").show().html("<p>距离本次团购结束还有:</p><p><span style='color:red;font-size:14px;'>" +showTime+"</span></p>");
h--;
if(h<=0)
{
endTime--;
h=9;
}
}
我这个是每0.1秒执行一次
如果你是每秒执行一次取消h
Math裏面需要數字運算。
你的那個window.name是什麽來的?字符串??
出來的結果不是數字。所以現時Nan
1. 被0除
2. 不合法的字符串转换成数值
3. 数值过大。
还有一种就是浏览器兼容的问题导致的。