function update(url,odj){
var ajax = ((typeof XMLHttpRequest == 'function') ? new XMLHttpReuest() : new ActiveXObject('Microsoft.XMLHTTP'));
ajax.open('get',url,true);
ajax.onreadystatechange = function(){
var flag = false,time;
if(ajax.readyState == 4 && ajax.status == 200){
if(ajax.responseText != null){
flag = true;
clearTimeout(time);
$('Progress').style.display = 'none';
$('Progress').style.backgroundColor = '';
}
}else{
(function(){
$('Progress').style.display = 'block';
with($('Progress').firstChild.style){
if(parseInt(marginRight) > 0){
marginRight = parseInt(marginRight) - 1;
}else{
$('Progress').style.backgroundColor = backgroundColor;
marginRight = 125;
backgroundColor = backgroundColor == '#fff' ? '#600' : '#fff';
}
}
time = setTimeout(arguments.callee,10);
})();
}
}
ajax.send(null);
}无法结束setTimeout 求各位大神看看那里的问题
var ajax = ((typeof XMLHttpRequest == 'function') ? new XMLHttpReuest() : new ActiveXObject('Microsoft.XMLHTTP'));
ajax.open('get',url,true);
ajax.onreadystatechange = function(){
var flag = false,time;
if(ajax.readyState == 4 && ajax.status == 200){
if(ajax.responseText != null){
flag = true;
clearTimeout(time);
$('Progress').style.display = 'none';
$('Progress').style.backgroundColor = '';
}
}else{
(function(){
$('Progress').style.display = 'block';
with($('Progress').firstChild.style){
if(parseInt(marginRight) > 0){
marginRight = parseInt(marginRight) - 1;
}else{
$('Progress').style.backgroundColor = backgroundColor;
marginRight = 125;
backgroundColor = backgroundColor == '#fff' ? '#600' : '#fff';
}
}
time = setTimeout(arguments.callee,10);
})();
}
}
ajax.send(null);
}无法结束setTimeout 求各位大神看看那里的问题
function update(url,odj){
var ajax = ((typeof XMLHttpRequest == 'function') ? new XMLHttpReuest() : new ActiveXObject('Microsoft.XMLHTTP'));
ajax.open('get',url,true);
ajax.onreadystatechange = function(){
var flag = false;
if(ajax.readyState == 4 && ajax.status == 200){
if(ajax.responseText != null){
flag = true;
clearTimeout(time);
$('Progress').style.display = 'none';
$('Progress').style.backgroundColor = '';
}
}else{
(function(){
$('Progress').style.display = 'block';
with($('Progress').firstChild.style){
if(parseInt(marginRight) > 0){
marginRight = parseInt(marginRight) - 1;
}else{
$('Progress').style.backgroundColor = backgroundColor;
marginRight = 125;
backgroundColor = backgroundColor == '#fff' ? '#600' : '#fff';
}
}
time = setTimeout(arguments.callee,10);
})();
}
}
ajax.send(null);
}
http://www.clskj.com/dmg/default.php
点第一test可以看到效果
$('Progress').style.display = 'block';
with($('Progress').firstChild.style){
if(parseInt(marginRight) > 0){
marginRight = parseInt(marginRight) - 1;
}else{
$('Progress').style.backgroundColor = backgroundColor;
marginRight = 125;
backgroundColor = backgroundColor == '#fff' ? '#600' : '#fff';
}
}
time = setTimeout(arguments.callee,10);
})(time);
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>首页</title>
<style type="text/css">
#opt_menu{
list-style:none;
margin:0;
padding:0;
}
#opt_menu li {
display:inline;
}
#opt_menu li a{
float:left;
display:block;
width:125px;
height:125px;
text-decoration:none;
text-align:center;
line-height:125px;
vertical-align:middle;
color:#900;
}
</style>
</head>
<body>
<div style="width:800px;height:500px; margin:auto; border:1px solid #EFEFEF;padding:25px">
<div style="float:left;width:500px;height:350px;border:1px solid #000; position:relative">
<div id="Form1"></div>
<div id="Progress" style="display:none;position:absolute; width:125px;height:2px;font-size:0px; left:195px; top:172.5px; border:1px solid #CCC">
<div style="background:#600;margin-right:125px;height:2px;font-size:0px;"></div>
</div>
</div>
<div style="float:right;width:280px;height:500px;border:1px solid #000">
</div>
<div style="float:left;width:500px;height:125px;margin-top:25px;border:1px solid #000">
<ul id="opt_menu">
<li><a href="javascript:void(0)" onclick="update('/dmg/default.php',Form1)">test</a></li>
<li><a href="javascript:void(0)">test</a></li>
<li><a href="javascript:void(0)">test</a></li>
<li><a href="javascript:void(0)">test</a></li>
</ul>
</div>
</div>
<script type="text/javascript">
<!--
function $(id){
return document.getElementById(id);
}
var time;
function update(url,odj){
clearTimeout(time);
var ajax = ((typeof XMLHttpRequest == 'function') ? new XMLHttpReuest() : new ActiveXObject('Microsoft.XMLHTTP'));
ajax.open('get',url,true);
ajax.onreadystatechange = function(){
var flag = false;
if(ajax.readyState == 4 && ajax.status == 200){
if(ajax.responseText != null){
flag = true;
clearTimeout(time);
alert(time);
$('Progress').style.display = 'none';
$('Progress').style.backgroundColor = '';
}
}else{
(function(){
$('Progress').style.display = 'block';
with($('Progress').firstChild.style){
if(parseInt(marginRight) > 0){
marginRight = parseInt(marginRight) - 1;
}else{
$('Progress').style.backgroundColor = backgroundColor;
marginRight = 125;
backgroundColor = backgroundColor == '#fff' ? '#600' : '#fff';
}
}
clearTimeout(time);
time = setTimeout(arguments.callee,10);
})();
}
}
ajax.send(null);
}
//-->
</script>
</body>
</html>
演示地址:
http://www.clskj.com/dmg/default.phpvar stop, time;
function update(url,odj){
stop = false;
var ajax = ((typeof XMLHttpRequest == 'function') ? new XMLHttpReuest() : new ActiveXObject('Microsoft.XMLHTTP'));
ajax.open('get',url,true);
ajax.onreadystatechange = function(){
if(ajax.readyState == 4 && ajax.status == 200){
if(ajax.responseText != null){
stop = true;
}
}else{
(function(){
if(!stop){
$('Progress').style.display = 'block';
with($('Progress').firstChild.style){
if(parseInt(marginRight) > 0){
marginRight = parseInt(marginRight) - 1;
}else{
$('Progress').style.backgroundColor = backgroundColor;
marginRight = 125;
backgroundColor = backgroundColor == '#fff' ? '#600' : '#fff';
}
}
time = setTimeout(arguments.callee,50);
}else{
$('Progress').style.display = 'none';
$('Progress').style.backgroundColor = '#fff';
$('Progress').firstChild.style.marginRight = 125;
$('Progress').firstChild.style.backgroundColor = '#600';
clearTimeout(time);
return;
}
})();
}
}
ajax.send(null);
}