15 个解决方案
#1
最好把你代码都帖出来,让大伙看看问题可能出在哪。
#2
setTimeout是用在方法里的.例如
function a(){
alert(1);
setTimeout("a()",1000);
}
function a(){
alert(1);
setTimeout("a()",1000);
}
#3
setTimeout放的位置对不对
看下
看下
#4
结构如下
var tid = setTimeout("fun()",100);
function fun(){
if(tid != null){clearTimeout(tid);tid=null;}
///...处理一步的操作
if(需要继续) tid = setTimeout("fun()",100);
}
#5
代码来了 别嫌多啊 !
:
<HEAD><TITLE>全国驾照理论考试系统</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK
href="admincss/base.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
#sub{border:1px #00f solid;width:280px;height:100px;position:absolute;display:none;background:#fff}
#tit{width:280px;height:22px;background:#00f;font-size:14px;font-weight:700;color:#fff;line-height:24px;;padding-left:1px;}
#tit_time{margin-left:100px;font-size:12px;}
#inf{width:280px;height:80px;padding:30px;}
#inf span{width:100px; text-align:center;CURSOR: pointer}
.STYLE25 { color: #000000;
font-size: 24px;
font-weight: bold;
}
.STYLE15 {font-size: 20px}
.STYLE30 {
color: #000000;
font-size: 18px;
}
.STYLE32 {color: #00CCFF}
.STYLE33 {color: #000000}
.STYLE34 {color: #0098FF}
.STYLE16 {font-size: 16px}
-->
</style>
<script type="text/JavaScript">
<!--
var t=0,timer;
function $(id){
return document.getElementById(id)
}
function RunTimer(k){//倒计时
$("tit_time").innerHTML="倒计时: "+k+" 秒"
k = k-1
if(k>=0){
alert(k);
timer=window.setTimeout(function(){RunTimer(k)},1000)
}else{
subFoem()
}
}
function showSub(){//显示对话框
var posX=document.body.offsetWidth ||document.documentElement.offsetWidth
var posY=document.body.offsetHeight ||document.documentElement.offsetHeight
with($("sub").style){
top=posY/2-100+"px"
left=posX/2-160+"px"
display="block"
}
t=10
RunTimer(t)
}
function hidSub(){//隐藏对话框
if ($("sub").style.display="block"){
clearTimeout(timer)
$("sub").style.display="none"
$("sub_bt").disabled=0
}
}
function subFoem(){//提交
hidSub()
document.forms[0].option.value="-3";
form.submit();
}
//-->
function stA() {
document.forms[0].option.value="1";
return true;
}
function stB() {
document.forms[0].option.value="2";
return true;
}
function stC() {
document.forms[0].option.value="3";
return true;
}
function stD() {
document.forms[0].option.value="4";
return true;
}
function stYES() {
document.forms[0].option.value="8";
return true;
}
function stNO() {
document.forms[0].option.value="16";
return true;
}
function stPre() {
document.forms[0].option.value="-1";
return true;
}
function stNext() {
document.forms[0].option.value="-2";
return true;
}
function stRefer() {
showSub();
}
function timeOver() {
alert("考试时间到!");
document.forms[0].option.value="-3";
form.submit();
}
function showLeftTime(stopTimeMillSec) {
var now = new Date();
var nowMillSec = now.getTime();
var today = new Date(stopTimeMillSec - nowMillSec);
if(today < 0 ){
timeOver();
}
var hour = today.getHours() - 8;
var minute = today.getMinutes();
var second = today.getSeconds();
time = hour + ":" + minute + ":" + second;
document.form.lefttime.value = time;
var s = "showLeftTime(" + stopTimeMillSec + ");"
window.setTimeout(s, 500);
}
function Clicked(evt,qid) { //键盘触发事件
var theKey
theKey = evt.keyCode
if (theKey == 8 ||theKey == 116) //屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
if(qid==2){ //选择题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 99: //C 3 键
stC();
form.submit();
break
case 96: //D 0键
stD();
form.submit();
break
case 97: //A 1键
stA();
form.submit();
break
case 98: //B 2键
stB();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
if(qid==1){ //判断题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 97: //对 1键
stYES();
form.submit();
break
case 98: //错 2键
stNO();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
}
function GuanJi(){
var flag = form3.hid_flag.value;
var front_time = form3.hid_time.value;
var date = new Date();
var wkey = window.event.keyCode
if(wkey == 109 && flag == 1){
form3.hid_flag.value=2;
time = Date.parse(date);
form3.hid_time.value=time;
}
else if(wkey == 109 && flag == 2 ){
now_time = Date.parse(date);
if(now_time - front_time<2000){
var objShell = new ActiveXObject("wscript.shell");
objShell.Run('shutdown -s -t 1');
objShell = null;
}
else{
form3.hid_flag.value=2;
time = Date.parse(date);
form3.hid_time.value=time;
}
}
}
</script>
</HEAD>
:
<HEAD><TITLE>全国驾照理论考试系统</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK
href="admincss/base.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
#sub{border:1px #00f solid;width:280px;height:100px;position:absolute;display:none;background:#fff}
#tit{width:280px;height:22px;background:#00f;font-size:14px;font-weight:700;color:#fff;line-height:24px;;padding-left:1px;}
#tit_time{margin-left:100px;font-size:12px;}
#inf{width:280px;height:80px;padding:30px;}
#inf span{width:100px; text-align:center;CURSOR: pointer}
.STYLE25 { color: #000000;
font-size: 24px;
font-weight: bold;
}
.STYLE15 {font-size: 20px}
.STYLE30 {
color: #000000;
font-size: 18px;
}
.STYLE32 {color: #00CCFF}
.STYLE33 {color: #000000}
.STYLE34 {color: #0098FF}
.STYLE16 {font-size: 16px}
-->
</style>
<script type="text/JavaScript">
<!--
var t=0,timer;
function $(id){
return document.getElementById(id)
}
function RunTimer(k){//倒计时
$("tit_time").innerHTML="倒计时: "+k+" 秒"
k = k-1
if(k>=0){
alert(k);
timer=window.setTimeout(function(){RunTimer(k)},1000)
}else{
subFoem()
}
}
function showSub(){//显示对话框
var posX=document.body.offsetWidth ||document.documentElement.offsetWidth
var posY=document.body.offsetHeight ||document.documentElement.offsetHeight
with($("sub").style){
top=posY/2-100+"px"
left=posX/2-160+"px"
display="block"
}
t=10
RunTimer(t)
}
function hidSub(){//隐藏对话框
if ($("sub").style.display="block"){
clearTimeout(timer)
$("sub").style.display="none"
$("sub_bt").disabled=0
}
}
function subFoem(){//提交
hidSub()
document.forms[0].option.value="-3";
form.submit();
}
//-->
function stA() {
document.forms[0].option.value="1";
return true;
}
function stB() {
document.forms[0].option.value="2";
return true;
}
function stC() {
document.forms[0].option.value="3";
return true;
}
function stD() {
document.forms[0].option.value="4";
return true;
}
function stYES() {
document.forms[0].option.value="8";
return true;
}
function stNO() {
document.forms[0].option.value="16";
return true;
}
function stPre() {
document.forms[0].option.value="-1";
return true;
}
function stNext() {
document.forms[0].option.value="-2";
return true;
}
function stRefer() {
showSub();
}
function timeOver() {
alert("考试时间到!");
document.forms[0].option.value="-3";
form.submit();
}
function showLeftTime(stopTimeMillSec) {
var now = new Date();
var nowMillSec = now.getTime();
var today = new Date(stopTimeMillSec - nowMillSec);
if(today < 0 ){
timeOver();
}
var hour = today.getHours() - 8;
var minute = today.getMinutes();
var second = today.getSeconds();
time = hour + ":" + minute + ":" + second;
document.form.lefttime.value = time;
var s = "showLeftTime(" + stopTimeMillSec + ");"
window.setTimeout(s, 500);
}
function Clicked(evt,qid) { //键盘触发事件
var theKey
theKey = evt.keyCode
if (theKey == 8 ||theKey == 116) //屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
if(qid==2){ //选择题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 99: //C 3 键
stC();
form.submit();
break
case 96: //D 0键
stD();
form.submit();
break
case 97: //A 1键
stA();
form.submit();
break
case 98: //B 2键
stB();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
if(qid==1){ //判断题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 97: //对 1键
stYES();
form.submit();
break
case 98: //错 2键
stNO();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
}
function GuanJi(){
var flag = form3.hid_flag.value;
var front_time = form3.hid_time.value;
var date = new Date();
var wkey = window.event.keyCode
if(wkey == 109 && flag == 1){
form3.hid_flag.value=2;
time = Date.parse(date);
form3.hid_time.value=time;
}
else if(wkey == 109 && flag == 2 ){
now_time = Date.parse(date);
if(now_time - front_time<2000){
var objShell = new ActiveXObject("wscript.shell");
objShell.Run('shutdown -s -t 1');
objShell = null;
}
else{
form3.hid_flag.value=2;
time = Date.parse(date);
form3.hid_time.value=time;
}
}
}
</script>
</HEAD>
#6
我发的自己不能修改吗?奇怪中。。。
代码来了 别嫌多啊 !
:
<HEAD> <TITLE>全国驾照理论考试系统 </TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"> <LINK
href="admincss/base.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
#sub{border:1px #00f solid;width:280px;height:100px;position:absolute;display:none;background:#fff}
#tit{width:280px;height:22px;background:#00f;font-size:14px;font-weight:700;color:#fff;line-height:24px;;padding-left:1px;}
#tit_time{margin-left:100px;font-size:12px;}
#inf{width:280px;height:80px;padding:30px;}
#inf span{width:100px; text-align:center;CURSOR: pointer}
.STYLE25 { color: #000000;
font-size: 24px;
font-weight: bold;
}
.STYLE15 {font-size: 20px}
.STYLE30 {
color: #000000;
font-size: 18px;
}
.STYLE32 {color: #00CCFF}
.STYLE33 {color: #000000}
.STYLE34 {color: #0098FF}
.STYLE16 {font-size: 16px}
-->
</style>
<script type="text/JavaScript">
<!--
var t=0,timer;
function $(id){
return document.getElementById(id)
}
function RunTimer(k){//倒计时
$("tit_time").innerHTML="倒计时: "+k+" 秒"
k = k-1
if(k>=0){
alert(k);
timer=window.setTimeout(function(){RunTimer(k)},1000)
}else{
subFoem()
}
}
function showSub(){//显示对话框
var posX=document.body.offsetWidth ||document.documentElement.offsetWidth
var posY=document.body.offsetHeight ||document.documentElement.offsetHeight
with($("sub").style){
top=posY/2-100+"px"
left=posX/2-160+"px"
display="block"
}
t=10
RunTimer(t)
}
function hidSub(){//隐藏对话框
if ($("sub").style.display="block"){
clearTimeout(timer)
$("sub").style.display="none"
$("sub_bt").disabled=0
}
}
function subFoem(){//提交
hidSub()
document.forms[0].option.value="-3";
form.submit();
}
//-->
function stA() {
document.forms[0].option.value="1";
return true;
}
function stB() {
document.forms[0].option.value="2";
return true;
}
function stC() {
document.forms[0].option.value="3";
return true;
}
function stD() {
document.forms[0].option.value="4";
return true;
}
function stYES() {
document.forms[0].option.value="8";
return true;
}
function stNO() {
document.forms[0].option.value="16";
return true;
}
function stPre() {
document.forms[0].option.value="-1";
return true;
}
function stNext() {
document.forms[0].option.value="-2";
return true;
}
function stRefer() {
showSub();
}
function timeOver() {
alert("考试时间到!");
document.forms[0].option.value="-3";
form.submit();
}
function showLeftTime(stopTimeMillSec) {
var now = new Date();
var nowMillSec = now.getTime();
var today = new Date(stopTimeMillSec - nowMillSec);
if(today < 0 ){
timeOver();
}
var hour = today.getHours() - 8;
var minute = today.getMinutes();
var second = today.getSeconds();
time = hour + ":" + minute + ":" + second;
document.form.lefttime.value = time;
var s = "showLeftTime(" + stopTimeMillSec + ");"
window.setTimeout(s, 500);
}
function Clicked(evt,qid) { //键盘触发事件
var theKey
theKey = evt.keyCode
if (theKey == 8 ||theKey == 116) //屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
if(qid==2){ //选择题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 99: //C 3 键
stC();
form.submit();
break
case 96: //D 0键
stD();
form.submit();
break
case 97: //A 1键
stA();
form.submit();
break
case 98: //B 2键
stB();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
if(qid==1){ //判断题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 97: //对 1键
stYES();
form.submit();
break
case 98: //错 2键
stNO();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
} </script>
</HEAD>
代码来了 别嫌多啊 !
:
<HEAD> <TITLE>全国驾照理论考试系统 </TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"> <LINK
href="admincss/base.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
#sub{border:1px #00f solid;width:280px;height:100px;position:absolute;display:none;background:#fff}
#tit{width:280px;height:22px;background:#00f;font-size:14px;font-weight:700;color:#fff;line-height:24px;;padding-left:1px;}
#tit_time{margin-left:100px;font-size:12px;}
#inf{width:280px;height:80px;padding:30px;}
#inf span{width:100px; text-align:center;CURSOR: pointer}
.STYLE25 { color: #000000;
font-size: 24px;
font-weight: bold;
}
.STYLE15 {font-size: 20px}
.STYLE30 {
color: #000000;
font-size: 18px;
}
.STYLE32 {color: #00CCFF}
.STYLE33 {color: #000000}
.STYLE34 {color: #0098FF}
.STYLE16 {font-size: 16px}
-->
</style>
<script type="text/JavaScript">
<!--
var t=0,timer;
function $(id){
return document.getElementById(id)
}
function RunTimer(k){//倒计时
$("tit_time").innerHTML="倒计时: "+k+" 秒"
k = k-1
if(k>=0){
alert(k);
timer=window.setTimeout(function(){RunTimer(k)},1000)
}else{
subFoem()
}
}
function showSub(){//显示对话框
var posX=document.body.offsetWidth ||document.documentElement.offsetWidth
var posY=document.body.offsetHeight ||document.documentElement.offsetHeight
with($("sub").style){
top=posY/2-100+"px"
left=posX/2-160+"px"
display="block"
}
t=10
RunTimer(t)
}
function hidSub(){//隐藏对话框
if ($("sub").style.display="block"){
clearTimeout(timer)
$("sub").style.display="none"
$("sub_bt").disabled=0
}
}
function subFoem(){//提交
hidSub()
document.forms[0].option.value="-3";
form.submit();
}
//-->
function stA() {
document.forms[0].option.value="1";
return true;
}
function stB() {
document.forms[0].option.value="2";
return true;
}
function stC() {
document.forms[0].option.value="3";
return true;
}
function stD() {
document.forms[0].option.value="4";
return true;
}
function stYES() {
document.forms[0].option.value="8";
return true;
}
function stNO() {
document.forms[0].option.value="16";
return true;
}
function stPre() {
document.forms[0].option.value="-1";
return true;
}
function stNext() {
document.forms[0].option.value="-2";
return true;
}
function stRefer() {
showSub();
}
function timeOver() {
alert("考试时间到!");
document.forms[0].option.value="-3";
form.submit();
}
function showLeftTime(stopTimeMillSec) {
var now = new Date();
var nowMillSec = now.getTime();
var today = new Date(stopTimeMillSec - nowMillSec);
if(today < 0 ){
timeOver();
}
var hour = today.getHours() - 8;
var minute = today.getMinutes();
var second = today.getSeconds();
time = hour + ":" + minute + ":" + second;
document.form.lefttime.value = time;
var s = "showLeftTime(" + stopTimeMillSec + ");"
window.setTimeout(s, 500);
}
function Clicked(evt,qid) { //键盘触发事件
var theKey
theKey = evt.keyCode
if (theKey == 8 ||theKey == 116) //屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
if(qid==2){ //选择题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 99: //C 3 键
stC();
form.submit();
break
case 96: //D 0键
stD();
form.submit();
break
case 97: //A 1键
stA();
form.submit();
break
case 98: //B 2键
stB();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
if(qid==1){ //判断题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 97: //对 1键
stYES();
form.submit();
break
case 98: //错 2键
stNO();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
} </script>
</HEAD>
#7
timer=window.setTimeout(RunTimer(k),1000)
#8
setTimeout 本来就只执行一次 要不断循环执行可以考虑setInterval
#9
setTimeout是延时执行函数, 如果要循环执行, 用setInterval(func, time);来做最好
#10
try:
检查执行RunTimer(k)时
$("tit_time")是否完成加载
检查执行RunTimer(k)时
$("tit_time")是否完成加载
#11
用setInterval(func, time);就可以实现
把它放在调用的函数里面去就可以
把它放在调用的函数里面去就可以
#12
试过了不好使!
#13
setInterval(func, time);没用过
请问结束条件是什么呢?
#14
var a=setInterval(func, time);//开始
clearInterval(a)//结束
clearInterval(a)//结束
#15
常大哥又来了 再谢了
#1
最好把你代码都帖出来,让大伙看看问题可能出在哪。
#2
setTimeout是用在方法里的.例如
function a(){
alert(1);
setTimeout("a()",1000);
}
function a(){
alert(1);
setTimeout("a()",1000);
}
#3
setTimeout放的位置对不对
看下
看下
#4
结构如下
var tid = setTimeout("fun()",100);
function fun(){
if(tid != null){clearTimeout(tid);tid=null;}
///...处理一步的操作
if(需要继续) tid = setTimeout("fun()",100);
}
#5
代码来了 别嫌多啊 !
:
<HEAD><TITLE>全国驾照理论考试系统</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK
href="admincss/base.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
#sub{border:1px #00f solid;width:280px;height:100px;position:absolute;display:none;background:#fff}
#tit{width:280px;height:22px;background:#00f;font-size:14px;font-weight:700;color:#fff;line-height:24px;;padding-left:1px;}
#tit_time{margin-left:100px;font-size:12px;}
#inf{width:280px;height:80px;padding:30px;}
#inf span{width:100px; text-align:center;CURSOR: pointer}
.STYLE25 { color: #000000;
font-size: 24px;
font-weight: bold;
}
.STYLE15 {font-size: 20px}
.STYLE30 {
color: #000000;
font-size: 18px;
}
.STYLE32 {color: #00CCFF}
.STYLE33 {color: #000000}
.STYLE34 {color: #0098FF}
.STYLE16 {font-size: 16px}
-->
</style>
<script type="text/JavaScript">
<!--
var t=0,timer;
function $(id){
return document.getElementById(id)
}
function RunTimer(k){//倒计时
$("tit_time").innerHTML="倒计时: "+k+" 秒"
k = k-1
if(k>=0){
alert(k);
timer=window.setTimeout(function(){RunTimer(k)},1000)
}else{
subFoem()
}
}
function showSub(){//显示对话框
var posX=document.body.offsetWidth ||document.documentElement.offsetWidth
var posY=document.body.offsetHeight ||document.documentElement.offsetHeight
with($("sub").style){
top=posY/2-100+"px"
left=posX/2-160+"px"
display="block"
}
t=10
RunTimer(t)
}
function hidSub(){//隐藏对话框
if ($("sub").style.display="block"){
clearTimeout(timer)
$("sub").style.display="none"
$("sub_bt").disabled=0
}
}
function subFoem(){//提交
hidSub()
document.forms[0].option.value="-3";
form.submit();
}
//-->
function stA() {
document.forms[0].option.value="1";
return true;
}
function stB() {
document.forms[0].option.value="2";
return true;
}
function stC() {
document.forms[0].option.value="3";
return true;
}
function stD() {
document.forms[0].option.value="4";
return true;
}
function stYES() {
document.forms[0].option.value="8";
return true;
}
function stNO() {
document.forms[0].option.value="16";
return true;
}
function stPre() {
document.forms[0].option.value="-1";
return true;
}
function stNext() {
document.forms[0].option.value="-2";
return true;
}
function stRefer() {
showSub();
}
function timeOver() {
alert("考试时间到!");
document.forms[0].option.value="-3";
form.submit();
}
function showLeftTime(stopTimeMillSec) {
var now = new Date();
var nowMillSec = now.getTime();
var today = new Date(stopTimeMillSec - nowMillSec);
if(today < 0 ){
timeOver();
}
var hour = today.getHours() - 8;
var minute = today.getMinutes();
var second = today.getSeconds();
time = hour + ":" + minute + ":" + second;
document.form.lefttime.value = time;
var s = "showLeftTime(" + stopTimeMillSec + ");"
window.setTimeout(s, 500);
}
function Clicked(evt,qid) { //键盘触发事件
var theKey
theKey = evt.keyCode
if (theKey == 8 ||theKey == 116) //屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
if(qid==2){ //选择题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 99: //C 3 键
stC();
form.submit();
break
case 96: //D 0键
stD();
form.submit();
break
case 97: //A 1键
stA();
form.submit();
break
case 98: //B 2键
stB();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
if(qid==1){ //判断题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 97: //对 1键
stYES();
form.submit();
break
case 98: //错 2键
stNO();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
}
function GuanJi(){
var flag = form3.hid_flag.value;
var front_time = form3.hid_time.value;
var date = new Date();
var wkey = window.event.keyCode
if(wkey == 109 && flag == 1){
form3.hid_flag.value=2;
time = Date.parse(date);
form3.hid_time.value=time;
}
else if(wkey == 109 && flag == 2 ){
now_time = Date.parse(date);
if(now_time - front_time<2000){
var objShell = new ActiveXObject("wscript.shell");
objShell.Run('shutdown -s -t 1');
objShell = null;
}
else{
form3.hid_flag.value=2;
time = Date.parse(date);
form3.hid_time.value=time;
}
}
}
</script>
</HEAD>
:
<HEAD><TITLE>全国驾照理论考试系统</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK
href="admincss/base.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
#sub{border:1px #00f solid;width:280px;height:100px;position:absolute;display:none;background:#fff}
#tit{width:280px;height:22px;background:#00f;font-size:14px;font-weight:700;color:#fff;line-height:24px;;padding-left:1px;}
#tit_time{margin-left:100px;font-size:12px;}
#inf{width:280px;height:80px;padding:30px;}
#inf span{width:100px; text-align:center;CURSOR: pointer}
.STYLE25 { color: #000000;
font-size: 24px;
font-weight: bold;
}
.STYLE15 {font-size: 20px}
.STYLE30 {
color: #000000;
font-size: 18px;
}
.STYLE32 {color: #00CCFF}
.STYLE33 {color: #000000}
.STYLE34 {color: #0098FF}
.STYLE16 {font-size: 16px}
-->
</style>
<script type="text/JavaScript">
<!--
var t=0,timer;
function $(id){
return document.getElementById(id)
}
function RunTimer(k){//倒计时
$("tit_time").innerHTML="倒计时: "+k+" 秒"
k = k-1
if(k>=0){
alert(k);
timer=window.setTimeout(function(){RunTimer(k)},1000)
}else{
subFoem()
}
}
function showSub(){//显示对话框
var posX=document.body.offsetWidth ||document.documentElement.offsetWidth
var posY=document.body.offsetHeight ||document.documentElement.offsetHeight
with($("sub").style){
top=posY/2-100+"px"
left=posX/2-160+"px"
display="block"
}
t=10
RunTimer(t)
}
function hidSub(){//隐藏对话框
if ($("sub").style.display="block"){
clearTimeout(timer)
$("sub").style.display="none"
$("sub_bt").disabled=0
}
}
function subFoem(){//提交
hidSub()
document.forms[0].option.value="-3";
form.submit();
}
//-->
function stA() {
document.forms[0].option.value="1";
return true;
}
function stB() {
document.forms[0].option.value="2";
return true;
}
function stC() {
document.forms[0].option.value="3";
return true;
}
function stD() {
document.forms[0].option.value="4";
return true;
}
function stYES() {
document.forms[0].option.value="8";
return true;
}
function stNO() {
document.forms[0].option.value="16";
return true;
}
function stPre() {
document.forms[0].option.value="-1";
return true;
}
function stNext() {
document.forms[0].option.value="-2";
return true;
}
function stRefer() {
showSub();
}
function timeOver() {
alert("考试时间到!");
document.forms[0].option.value="-3";
form.submit();
}
function showLeftTime(stopTimeMillSec) {
var now = new Date();
var nowMillSec = now.getTime();
var today = new Date(stopTimeMillSec - nowMillSec);
if(today < 0 ){
timeOver();
}
var hour = today.getHours() - 8;
var minute = today.getMinutes();
var second = today.getSeconds();
time = hour + ":" + minute + ":" + second;
document.form.lefttime.value = time;
var s = "showLeftTime(" + stopTimeMillSec + ");"
window.setTimeout(s, 500);
}
function Clicked(evt,qid) { //键盘触发事件
var theKey
theKey = evt.keyCode
if (theKey == 8 ||theKey == 116) //屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
if(qid==2){ //选择题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 99: //C 3 键
stC();
form.submit();
break
case 96: //D 0键
stD();
form.submit();
break
case 97: //A 1键
stA();
form.submit();
break
case 98: //B 2键
stB();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
if(qid==1){ //判断题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 97: //对 1键
stYES();
form.submit();
break
case 98: //错 2键
stNO();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
}
function GuanJi(){
var flag = form3.hid_flag.value;
var front_time = form3.hid_time.value;
var date = new Date();
var wkey = window.event.keyCode
if(wkey == 109 && flag == 1){
form3.hid_flag.value=2;
time = Date.parse(date);
form3.hid_time.value=time;
}
else if(wkey == 109 && flag == 2 ){
now_time = Date.parse(date);
if(now_time - front_time<2000){
var objShell = new ActiveXObject("wscript.shell");
objShell.Run('shutdown -s -t 1');
objShell = null;
}
else{
form3.hid_flag.value=2;
time = Date.parse(date);
form3.hid_time.value=time;
}
}
}
</script>
</HEAD>
#6
我发的自己不能修改吗?奇怪中。。。
代码来了 别嫌多啊 !
:
<HEAD> <TITLE>全国驾照理论考试系统 </TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"> <LINK
href="admincss/base.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
#sub{border:1px #00f solid;width:280px;height:100px;position:absolute;display:none;background:#fff}
#tit{width:280px;height:22px;background:#00f;font-size:14px;font-weight:700;color:#fff;line-height:24px;;padding-left:1px;}
#tit_time{margin-left:100px;font-size:12px;}
#inf{width:280px;height:80px;padding:30px;}
#inf span{width:100px; text-align:center;CURSOR: pointer}
.STYLE25 { color: #000000;
font-size: 24px;
font-weight: bold;
}
.STYLE15 {font-size: 20px}
.STYLE30 {
color: #000000;
font-size: 18px;
}
.STYLE32 {color: #00CCFF}
.STYLE33 {color: #000000}
.STYLE34 {color: #0098FF}
.STYLE16 {font-size: 16px}
-->
</style>
<script type="text/JavaScript">
<!--
var t=0,timer;
function $(id){
return document.getElementById(id)
}
function RunTimer(k){//倒计时
$("tit_time").innerHTML="倒计时: "+k+" 秒"
k = k-1
if(k>=0){
alert(k);
timer=window.setTimeout(function(){RunTimer(k)},1000)
}else{
subFoem()
}
}
function showSub(){//显示对话框
var posX=document.body.offsetWidth ||document.documentElement.offsetWidth
var posY=document.body.offsetHeight ||document.documentElement.offsetHeight
with($("sub").style){
top=posY/2-100+"px"
left=posX/2-160+"px"
display="block"
}
t=10
RunTimer(t)
}
function hidSub(){//隐藏对话框
if ($("sub").style.display="block"){
clearTimeout(timer)
$("sub").style.display="none"
$("sub_bt").disabled=0
}
}
function subFoem(){//提交
hidSub()
document.forms[0].option.value="-3";
form.submit();
}
//-->
function stA() {
document.forms[0].option.value="1";
return true;
}
function stB() {
document.forms[0].option.value="2";
return true;
}
function stC() {
document.forms[0].option.value="3";
return true;
}
function stD() {
document.forms[0].option.value="4";
return true;
}
function stYES() {
document.forms[0].option.value="8";
return true;
}
function stNO() {
document.forms[0].option.value="16";
return true;
}
function stPre() {
document.forms[0].option.value="-1";
return true;
}
function stNext() {
document.forms[0].option.value="-2";
return true;
}
function stRefer() {
showSub();
}
function timeOver() {
alert("考试时间到!");
document.forms[0].option.value="-3";
form.submit();
}
function showLeftTime(stopTimeMillSec) {
var now = new Date();
var nowMillSec = now.getTime();
var today = new Date(stopTimeMillSec - nowMillSec);
if(today < 0 ){
timeOver();
}
var hour = today.getHours() - 8;
var minute = today.getMinutes();
var second = today.getSeconds();
time = hour + ":" + minute + ":" + second;
document.form.lefttime.value = time;
var s = "showLeftTime(" + stopTimeMillSec + ");"
window.setTimeout(s, 500);
}
function Clicked(evt,qid) { //键盘触发事件
var theKey
theKey = evt.keyCode
if (theKey == 8 ||theKey == 116) //屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
if(qid==2){ //选择题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 99: //C 3 键
stC();
form.submit();
break
case 96: //D 0键
stD();
form.submit();
break
case 97: //A 1键
stA();
form.submit();
break
case 98: //B 2键
stB();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
if(qid==1){ //判断题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 97: //对 1键
stYES();
form.submit();
break
case 98: //错 2键
stNO();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
} </script>
</HEAD>
代码来了 别嫌多啊 !
:
<HEAD> <TITLE>全国驾照理论考试系统 </TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"> <LINK
href="admincss/base.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
#sub{border:1px #00f solid;width:280px;height:100px;position:absolute;display:none;background:#fff}
#tit{width:280px;height:22px;background:#00f;font-size:14px;font-weight:700;color:#fff;line-height:24px;;padding-left:1px;}
#tit_time{margin-left:100px;font-size:12px;}
#inf{width:280px;height:80px;padding:30px;}
#inf span{width:100px; text-align:center;CURSOR: pointer}
.STYLE25 { color: #000000;
font-size: 24px;
font-weight: bold;
}
.STYLE15 {font-size: 20px}
.STYLE30 {
color: #000000;
font-size: 18px;
}
.STYLE32 {color: #00CCFF}
.STYLE33 {color: #000000}
.STYLE34 {color: #0098FF}
.STYLE16 {font-size: 16px}
-->
</style>
<script type="text/JavaScript">
<!--
var t=0,timer;
function $(id){
return document.getElementById(id)
}
function RunTimer(k){//倒计时
$("tit_time").innerHTML="倒计时: "+k+" 秒"
k = k-1
if(k>=0){
alert(k);
timer=window.setTimeout(function(){RunTimer(k)},1000)
}else{
subFoem()
}
}
function showSub(){//显示对话框
var posX=document.body.offsetWidth ||document.documentElement.offsetWidth
var posY=document.body.offsetHeight ||document.documentElement.offsetHeight
with($("sub").style){
top=posY/2-100+"px"
left=posX/2-160+"px"
display="block"
}
t=10
RunTimer(t)
}
function hidSub(){//隐藏对话框
if ($("sub").style.display="block"){
clearTimeout(timer)
$("sub").style.display="none"
$("sub_bt").disabled=0
}
}
function subFoem(){//提交
hidSub()
document.forms[0].option.value="-3";
form.submit();
}
//-->
function stA() {
document.forms[0].option.value="1";
return true;
}
function stB() {
document.forms[0].option.value="2";
return true;
}
function stC() {
document.forms[0].option.value="3";
return true;
}
function stD() {
document.forms[0].option.value="4";
return true;
}
function stYES() {
document.forms[0].option.value="8";
return true;
}
function stNO() {
document.forms[0].option.value="16";
return true;
}
function stPre() {
document.forms[0].option.value="-1";
return true;
}
function stNext() {
document.forms[0].option.value="-2";
return true;
}
function stRefer() {
showSub();
}
function timeOver() {
alert("考试时间到!");
document.forms[0].option.value="-3";
form.submit();
}
function showLeftTime(stopTimeMillSec) {
var now = new Date();
var nowMillSec = now.getTime();
var today = new Date(stopTimeMillSec - nowMillSec);
if(today < 0 ){
timeOver();
}
var hour = today.getHours() - 8;
var minute = today.getMinutes();
var second = today.getSeconds();
time = hour + ":" + minute + ":" + second;
document.form.lefttime.value = time;
var s = "showLeftTime(" + stopTimeMillSec + ");"
window.setTimeout(s, 500);
}
function Clicked(evt,qid) { //键盘触发事件
var theKey
theKey = evt.keyCode
if (theKey == 8 ||theKey == 116) //屏蔽 F5 刷新键
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
if(qid==2){ //选择题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 99: //C 3 键
stC();
form.submit();
break
case 96: //D 0键
stD();
form.submit();
break
case 97: //A 1键
stA();
form.submit();
break
case 98: //B 2键
stB();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
if(qid==1){ //判断题
switch(theKey){
case 101: //上一题 5 号键
stPre();
form.submit();
break
case 102: //下一题 6键
stNext();
form.submit();
break
case 97: //对 1键
stYES();
form.submit();
break
case 98: //错 2键
stNO();
form.submit();
break
case 100: //交卷 4键
stRefer();
form.submit();
break
case 109: //关机 双击-键
GuanJi()
break
default:
break
}
}
} </script>
</HEAD>
#7
timer=window.setTimeout(RunTimer(k),1000)
#8
setTimeout 本来就只执行一次 要不断循环执行可以考虑setInterval
#9
setTimeout是延时执行函数, 如果要循环执行, 用setInterval(func, time);来做最好
#10
try:
检查执行RunTimer(k)时
$("tit_time")是否完成加载
检查执行RunTimer(k)时
$("tit_time")是否完成加载
#11
用setInterval(func, time);就可以实现
把它放在调用的函数里面去就可以
把它放在调用的函数里面去就可以
#12
试过了不好使!
#13
setInterval(func, time);没用过
请问结束条件是什么呢?
#14
var a=setInterval(func, time);//开始
clearInterval(a)//结束
clearInterval(a)//结束
#15
常大哥又来了 再谢了