JS cleartimeout()不起作用
<html><head><title>location对象</title><scripttype="text/javascript">vari=1;functionzhu...
<html>
<head>
<title>location对象</title>
<script type="text/javascript">
var i=1;
function zhuanhuan(n)
{
if(n)
{
var newwin=window.open("","newwindow","height=600,width=800");
switch(i)
{
case 1:
newwin.location.replace("onkeyup.html");
break;
case 2:
newwin.location.replace("push.html");
break;
case 3:
newwin.location.replace("下拉表单.html");
break;
case 4:
newwin.location.replace("Date对象.html");
break;
}
i++;
if(i>4)
{
i=1;
}
var j=self.setTimeout("zhuanhuan(1)",3000);
}
else {clearTimeout(j);}
}
</script>
</head>
<body>
<input type="button" onclick="zhuanhuan(1)" value="转换"/>
<input type="button" onclick="zhuanhuan(0)" value="停止"/>
</body>
</html>
我想按一下“转换”开始换网页,按“停止”转换停止,再按“转换“又开始变。
但停止不了 cleartimeout()没起作用吗? 展开
<head>
<title>location对象</title>
<script type="text/javascript">
var i=1;
function zhuanhuan(n)
{
if(n)
{
var newwin=window.open("","newwindow","height=600,width=800");
switch(i)
{
case 1:
newwin.location.replace("onkeyup.html");
break;
case 2:
newwin.location.replace("push.html");
break;
case 3:
newwin.location.replace("下拉表单.html");
break;
case 4:
newwin.location.replace("Date对象.html");
break;
}
i++;
if(i>4)
{
i=1;
}
var j=self.setTimeout("zhuanhuan(1)",3000);
}
else {clearTimeout(j);}
}
</script>
</head>
<body>
<input type="button" onclick="zhuanhuan(1)" value="转换"/>
<input type="button" onclick="zhuanhuan(0)" value="停止"/>
</body>
</html>
我想按一下“转换”开始换网页,按“停止”转换停止,再按“转换“又开始变。
但停止不了 cleartimeout()没起作用吗? 展开
1个回答
展开全部
改成这样
你那样,j一直在变,而且一直在settimeout 你关的时候,只关了一个
<script type="text/javascript">
var i = 1;
var j = 0;
function zhuanhuan(n) {
if (n) {
var newwin = window.open("", "newwindow", "height=600,width=800");
switch (i) {
case 1:
newwin.location.replace("onkeyup.html");
break;
case 2:
newwin.location.replace("push.html");
break;
case 3:
newwin.location.replace("下拉表单.html");
break;
case 4:
newwin.location.replace("Date对象.html");
break;
}
i++;
if (i > 4) {
i = 1;
}
if (j != 0) {
j = self.setTimeout("zhuanhuan(1)", 3000);
}
}
else {
clearTimeout(j);
}
}
</script>
你那样,j一直在变,而且一直在settimeout 你关的时候,只关了一个
<script type="text/javascript">
var i = 1;
var j = 0;
function zhuanhuan(n) {
if (n) {
var newwin = window.open("", "newwindow", "height=600,width=800");
switch (i) {
case 1:
newwin.location.replace("onkeyup.html");
break;
case 2:
newwin.location.replace("push.html");
break;
case 3:
newwin.location.replace("下拉表单.html");
break;
case 4:
newwin.location.replace("Date对象.html");
break;
}
i++;
if (i > 4) {
i = 1;
}
if (j != 0) {
j = self.setTimeout("zhuanhuan(1)", 3000);
}
}
else {
clearTimeout(j);
}
}
</script>
追问
这样写j不一直都是0吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询