下面程序中为什么暂停程序无效,请各位帮忙修正!!
function PrintImage()
{
var tiff;
tiff="",num="<%=printnum%>";
for(var i=1;i<=num;i++)
{
tiff= "tiff" + i;
if (document.getElementById(tiff).GetValue(9)==2480)
{
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("cmd /k c://2.bat");
}
else if (document.getElementById(tiff).GetValue(9)==4961)
{
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("cmd /k c://3.bat");
}
try {
Thread.sleep(5000); //由类名调用
} catch (InterruptedException e) {
return;
document.getElementById(tiff).Print(4);
}
}
function PrintImage()
{
var tiff;
tiff="",num="<%=printnum%>";
for(var i=1;i<=num;i++)
{
tiff= "tiff" + i;
if (document.getElementById(tiff).GetValue(9)==2480)
{
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("cmd /k c://2.bat");
}
else if (document.getElementById(tiff).GetValue(9)==4961)
{
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("cmd /k c://3.bat");
}
try {
Thread.sleep(5000); //由类名调用
} catch (InterruptedException e) {
return;
document.getElementById(tiff).Print(4);
}
}
=>
WScript.sleep(5000);
不能使用Java的语法来用吧
function pause(){
alert('我要暂停了!');
setTimeout(function(){
alert('我暂停了吧?');
},5000);
}
function Sleep(obj,iMinSecond)
{
if (window.eventList==null)
window.eventList=new Array();
var ind=-1;
for (var i=0;i<window.eventList.length;i++)
{
if (window.eventList[i]==null)
{
window.eventList[i]=obj;
ind=i;
break;
}
}
if (ind==-1)
{
ind=window.eventList.length;
window.eventList[ind]=obj;
}
setTimeout("GoOn(" + ind + ")",iMinSecond);
}
function GoOn(ind)
{
var obj=window.eventList[ind];
window.eventList[ind]=null;
if (obj.NextStep) obj.NextStep();
else obj();
}
function Test()
这句不能达到我的效果,程序没有进入sleep状态
没有起到暂停效果,我需要8楼代码效果,但要去除弹出框“sleep”
function Sleep(obj,iMinSecond)
{
if (window.eventList==null)
window.eventList=new Array();
var ind=-1;
for (var i=0;i<window.eventList.length;i++)
{
if (window.eventList[i]==null)
{
window.eventList[i]=obj;
ind=i;
break;
}
}
if (ind==-1)
{
ind=window.eventList.length;
window.eventList[ind]=obj;
}
setTimeout("GoOn(" + ind + ")",iMinSecond);
}
function GoOn(ind)
{
var obj=window.eventList[ind];
window.eventList[ind]=null;
if (obj.NextStep) obj.NextStep();
else obj();
}
function Test()
{
alert("sleep");
Sleep(this,10000);
this.NextStep=function()
{
alert("continue");
}
}
Test();
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Sleep(obj,iMinSecond)
{
if (window.eventList==null)
window.eventList=new Array();
var ind=-1;
for (var i=0;i<window.eventList.length;i++)
{
if (window.eventList[i]==null)
{
window.eventList[i]=obj;
ind=i;
break;
}
}
if (ind==-1)
{
ind=window.eventList.length;
window.eventList[ind]=obj;
}
setTimeout("GoOn(" + ind + ")",iMinSecond);
}
function GoOn(ind)
{
var obj=window.eventList[ind];
window.eventList[ind]=null;
if (obj.NextStep) obj.NextStep();
else obj();
}
function Test()
{
//alert("sleep");
Sleep(this,5000);
document.write("此方法开始沉睡5秒");
this.NextStep=function()
{
alert("continue");
document.write("方法开始了,沉睡结束");
}
}
Test();
//-->
</SCRIPT>
</BODY>
</HTML>
document.write("方法开始了,沉睡结束");
都屏蔽掉!在语句前加//
//document.write("此方法开始沉睡5秒");
//document.write("方法开始了,沉睡结束");汗啊~~~LZ貌似对js一点都不了解!
程序并没有得到暂停,按照12楼做法效果是:当点击弹出框“sleep”,程序会继续,不点则停留在那个界面上
js没有让程序暂停的函数 只能用 setTimeout 和 setInterval 来延迟执行