在线求显示剩余时间的ASP代码

hgxhgxhgx 2009-10-18 10:10:30
原程序大致如下,可以正常运行。现想加上显示剩余时间的功能,如3分钟倒计时,如果时间到,强制执行提交按钮或执行文件answer.asp。在线求代码。

<% @LANGUAGE=VBSCRIPT %>
<!--#include file="inc/function.asp"-->
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html><head><title>测试</title></head>

<body topmargin="0" style="margin:0; text-align: center; text-indent:0; word-spacing:0; line-height:100%" leftmargin="0">

<%
DIM rst
SET Cn=Server.CreateObject("ADODB.Connection")
Cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("test\shuxue.mdb")
set rst=server.createobject("ADODB.Recordset")
%>
<table width="791" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td height="93" align="center" valign=middle >
<font style=font-size:9pt;><b>测试</b></font> </td></tr>
<tr>
<td width="789">
<table width="749" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>

<td width="1039" height="200" class="news1" id="newsbody"> <font color=#424242>
<form method="post" action="answer.asp">

<font style=font-size:9pt;> <br>

<%
strsql="select * from shuxue "
rst.close
rst.open strsql,cn,1,1
rst.AbsolutePosition=cint(1)
s=rst("text")
response.write "【第1题】"&s
%>


<center><input type=submit name="B8" value="提交"></center>
<BR>
</form>
<%
rst.close
set rst=nothing
%> </font>

</font>

</td>
</tr>

</table>

</td>
</tr>
<tr>

</tr>
</table>
</body>
</html>
...全文
299 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzhqiao 2009-10-18
  • 打赏
  • 举报
回复
<form method="post" action="answer.asp"> 将表单加个名称
<form name="form1" method="post" action="answer.asp">
之后将document.location="answer.asp"这句改成
document.form1.submit();就行了。
hgxhgxhgx 2009-10-18
  • 打赏
  • 举报
回复
<% @LANGUAGE=VBSCRIPT %>
<!--#include file="inc/function.asp"-->
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html> <head> <title>测试 </title> <script language="javascript">
var dates=new Date();
var standate=new Date(dates.getYear(),dates.getMonth(),dates.getDate(),dates.getHours(),dates.getMinutes(),dates.getSeconds());
var betweendays=0;
var endminutes=10;

function setTimeEnd()
{
endminutes= endminutes - 1;
var strdisplay;
strdisplay=parseInt(endminutes / 60) + ":" + endminutes % 60
document.all.txtminute.value=strdisplay;
if (endminutes==0)
{
alert("时间到!");
document.location="answer.asp"
return;
}
setTimeout("setTimeEnd()",1000);
}


</script>

</head>

<body topmargin="0" style="margin:0; text-align: center; text-indent:0; word-spacing:0; line-height:100%" leftmargin="0" onload="setTimeEnd();">

<%
DIM rst
SET Cn=Server.CreateObject("ADODB.Connection")
Cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("test\shuxue.mdb")
set rst=server.createobject("ADODB.Recordset")
%>
<table width="791" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td height="93" align="center" valign=middle >
<font style=font-size:9pt;> <b>测试 </b> </font> </td> </tr>
<tr>
<td width="789">
<table width="749" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>

<td width="1039" height="200" class="news1" id="newsbody"> <font color=#424242>
<form method="post" action="answer.asp">

<font style=font-size:9pt;> <br>
参考时间:<input type="text" name="txtminute" value="00:00" > <br> <br>
<%
strsql="select * from shuxue "
rst.close
rst.open strsql,cn,1,1
rst.AbsolutePosition=cint(1)
s=rst("text")
response.write "【第1题】"&s
%>


<center> <input type=submit name="B8" value="提交"> </center>
<BR>
</form>
<%
rst.close
set rst=nothing
%> </font>

</font>

</td>
</tr>

</table>

</td>
</tr>
<tr>

</tr>
</table>
</body>
</html>

==========
上述红色字体的写法基本上可以达到要求了。

但语句document.location="answer.asp"虽然可以成功跳转,但之前答题作出的选择,如A/B/C等没有传递过去。继续在线求助,用什么语句来达到自动按“提交”
hgxhgxhgx 2009-10-18
  • 打赏
  • 举报
回复
各位大侠,不行喔。能不能就着我提供的代码来进行,拜托了
  • 打赏
  • 举报
回复
我写的解释很清楚了

你只要把你的程序放在上面的from当中,并且帮里面的连接改成你的提交连接即可
hgxhgxhgx 2009-10-18
  • 打赏
  • 举报
回复
刚才说的是:lzp4881兄的程序执行后,显示空白页面,原来的题没有显示,时间也没有显示
hgxhgxhgx 2009-10-18
  • 打赏
  • 举报
回复
不行喔,执行后,显示空白页面,原来的题没有显示,时间也没有显示
  • 打赏
  • 举报
回复
<FORM name=myform>剩余时间: <INPUT class=text2 size=10 value=剩余时间 
name=clock> <INPUT type=hidden size=50 name=times>
<%
Session("tryTime")="2008/9/9 09:50:00" '这里必须是设定的一个时间,你可以是在登陆的时候设置
TimeGet=Session("tryTime")''这是ASP控制的时间
%>
<SCRIPT language=JavaScript>
var id, iM = 0, iS = 1;
var start1 ="<%=TimeGet%>";
var start=new Date(start1)
if (document.myform.times.value==""){
starts=start.getTime();
}else{
starts=document.myform.times.value;
}
//document.myform.clock.value=start.getSeconds();
function go()
{
now = new Date();
time = (2700000-(now.getTime()-starts))/1000;
//time = (10000-(now.getTime()-starts))/1000;
time = Math.floor( time);
iS = time % 60;
iM = Math.floor( time / 60);

if ( iS < 10){
document.myform.clock.value = " " + iM + ":0" + iS;
}else{
document.myform.clock.value = " " + iM + ":" + iS;
}
document.myform.times.value =starts;
if (time==300){
alert("请抓紧时间答题,距交卷还有5分钟。");
}
if (time==0){
alert("时间到,请交卷。");
window.location="test.asp?gopage=jiaojuan&choose=" + document.form1.choose.value;
}
id = setTimeout( "go()", 1000);

}
go();
</SCRIPT>
</form>
lzp4881 2009-10-18
  • 打赏
  • 举报
回复
<% @LANGUAGE=VBSCRIPT %>
<!--#include file="inc/function.asp"-->
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html> <head> <title>测试 </title> </head>

<script type="text/JavaScript">

var timerRunning=false;
var timerID=null;
function stopclock(){
if(timerRunning) clearTimerout(timerID);
timerRunning=false;
}


function startclock(){
stopclock();
showtime();
}
var flag=0;
var TimeGetF=1;
var TimeNum=180;//180秒后提交
var TimeNumF,TimeNumM;
function showtime(){
TimeNum--;
TimeNumF=TimeNum/60;
TimeNumM=TimeNum%60;
if(TimeNum<0)
{
form1.submit();
}
var timue=" "+"你的时间还剩"+Math.floor(TimeNumF)+"分"+TimeNumM+"秒";
document.getElementById("display").innerText=timue;
timerID=setTimeout("showtime()",1000);
timerRunning=true;
}
</script>


<body topmargin="0" style="margin:0; text-align: center; text-indent:0; word-spacing:0; line-height:100%" leftmargin="0" onload="startclock()">

<%
DIM rst
SET Cn=Server.CreateObject("ADODB.Connection")
Cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("test\shuxue.mdb")
set rst=server.createobject("ADODB.Recordset")
%>
<table width="791" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td height="93" align="center" valign=middle >
<font style=font-size:9pt;> <b>测试 </b> </font> </td> </tr>
<tr>
<td width="789">
<table width="749" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>

<td width="1039" height="200" class="news1" id="newsbody"> <font color=#424242>
<form name="form1" method="post" action="answer.asp">

<font style=font-size:9pt;> <br>

<%
strsql="select * from shuxue "
rst.close
rst.open strsql,cn,1,1
rst.AbsolutePosition=cint(1)
s=rst("text")
response.write "【第1题】"&s
%>


<center> <input type=submit name="B8" value="提交"><div id="display"></div></center>
<BR>
</form>
<%
rst.close
set rst=nothing
%> </font>

</font>

</td>
</tr>

</table>

</td>
</tr>
<tr>

</tr>
</table>
</body>
</html>
hgxhgxhgx 2009-10-18
  • 打赏
  • 举报
回复
我是菜鸟,如何在我的程序中调用JS呢
春天的气息 2009-10-18
  • 打赏
  • 举报
回复
用个js控制一下就行了啦,你这个多数用于在线考试方面的。给你个例子,你参考一下!


题目:实现用户登陆后15分钟之后强制退出。
思路:
用JS写一个当前时间与登陆时间对比的方法。当两时间分钟值相减大于15时,那就用location.href跳转到退出的ASP页面。
疑问:怎样实现这JS方法的反复执行,以达到时间的对比?
解决办法:用JS的setTimeout函数可以解决这个疑问。


程序代码
<script language="JavaScript">
<!--
login_time=15;//设置允许登陆的时长,单位为分钟。
sm=<%=minute(session("in_time"))%>;//登陆时的分钟,session("in_time")为登陆时间。
sh=<%=hour(session("in_time"))%>;//登陆时的时钟,session("in_time")为登陆时间。
CheckTime();
function CheckTime(){//检查现在时间
nowtime= new Date();
nh=nowtime.getHours()
nm=nowtime.getMinutes()
if (nh > sh) nm +=60//当前时钟与登陆时的时钟做比较

//登陆时间超过login_time,退出
if ((snm - sm) > login_time){
alert("您登陆已经超过15分钟,系统将强制您退出!");
location.href("login_out.asp");
//parent.window.close();
}
delete nowtime;
setTimeout("CheckTime()","10000");//实现对CheckTime()方法的不停执行。10000为毫秒,1s=1000毫秒
}
-->
</script>

hgxhgxhgx 2009-10-18
  • 打赏
  • 举报
回复
已经OK,谢谢各位大侠

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧