求使用方法
<script type="text/javascript">var link = $('#stage').getElementsByTagName('li');
var count = 0;var btn = $('#ck_but');var speed = $('#dis_div');
var imgs = [],timeout = null;
var imgLoad = function (){btn.setAttribute('disabled','disabled',false);
var c=0;for(c = 0; c < link.length; c++){var s = {};
s.img = document.createElement('img');
s.url = $('#'+link.id+' a').href.replace(/:\d{3,}/,'');
s.url=s.url.substr(0,s.url.length-1);s.y = 6688;s.p = '/test.gif?';
s.c = 0;s.n = 0;s.t = 0;s.l = link.id;s.img.onerror = getError;
s.img.onload =getLoad;s.img.id = link.id+'_g';s.img.name=c;
s.lt = [];s.r = false;imgs = s;}c=0;
for(c in imgs){$.get("load.aspx", {array:imgs.url,i:c}, function (data, textStatus){
try{var y=data.split(',');imgs].y=data.split(',');}catch(e){}});}
btn.removeAttribute('disabled');}
var clear = function(c){clearTimeout(timeout);
timeout = null;if (!c) {
for (var i = link.length - 1; i >= 0; i--) {
if($('#'+link.id+' span').length>0){
$('#'+link.id+' span').className = '';
$('#'+link.id+' span').innerHTML = '';}};};}
var conn = function (c){clear(c);
btn.setAttribute('disabled','disabled',false);
if(link){var st,x;for(x in imgs){if(imgs.l==link.id){st=imgs.img.name;}}
if($("#"+link.id+ " span").length>0){$("#"+link.id+ " span").innerHTML = "連接中";
$("#"+link.id+ " span").className = "black";
imgs.img.src = imgs.url+':'+imgs.y+imgs.p+(Math.random()+'').replace('0.','');imgs.c=c;}
else{var span = document.createElement("span");span.id =link.id+'_g_s';
span.className='black';span.innerHTML = "連接中";$('#'+link.id+ ' div').appendChild(span);
imgs.img.src = imgs.url+':'+imgs.y+imgs.p+(Math.random()+'').replace('0.',''); imgs.c=c;;
speed.appendChild(imgs.img);}imgs.t = new Date().getTime();imgs.r = false;
timeout = setTimeout(function() {getError.call(imgs.img,c);}, 5000);
}else{btn.removeAttribute('disabled');};}
function getError(c){var st;if(typeof(c)!='number'){c=imgs.c;st=this.name;}
else{st= $('#'+link.id+"_g").name;}if($('#'+imgs.img.id+'_s')){
if (!imgs.r){imgs.n = 0;imgs.r = true;
if($('#'+imgs.img.id+'_s').innerHTML == '連接中'){
$('#'+imgs.img.id+'_s').className='br_reg white';
$('#'+imgs.img.id+'_s').innerHTML = '無法鏈接';}};
setTimeout(function(){conn(c+1);},500);}}
function getLoad(){var st=this.name==''?event.srcElement.name:this.name;
var end = new Date().getTime(),clink = imgs,
td = clink.n?end - imgs.t:end - imgs.t, total = 0;
imgs.lt.push(td);imgs.n += 1;if(imgs.r){return;}
if(imgs.n < 2 ){setTimeout(function(){conn(imgs.c);},500);
}else{for(var c = 0; c < 2; c ++){total += clink.lt;}
var time=(total/2).toFixed(2);if(time<=2000){
$('#'+imgs.img.id+'_s').className='br_green white';
$('#'+imgs.img.id+'_s').innerHTML = '流暢';}
else if(time>2000){
$('#'+imgs.img.id+'_s').className='br_ye white';
$('#'+imgs.img.id+'_s').innerHTML = '繁忙';}
else{
$('#'+imgs.img.id+'_s').className='br_reg white';
$('#'+imgs.img.id+'_s').innerHTML = '超時';}
count -= 1;imgs.n = 0;imgs.lt.length = 0;imgs.r = true;
setTimeout(function(){conn(imgs.c+1);},500);}}
imgLoad();
</script> 看不懂 不明觉厉
页:
[1]