记录,有需要的时候能用的上。
<p>
<a href="https://lanyou.vip" target="_blank">https://lanyou.vip</a> <span speed="https://lanyou.vip/" style="padding-left: 8px;">测速中</span>
</p>
<p>
<a href="https://www.baidu.com" target="_blank">https://www.baidu.com</a><span speed="https://www.baidu.com/" style="padding-left: 8px;">测速中</span>
</p>
<script>
var ping = 1;
setInterval("ping++", 1);
function test(i) {
$("span[speed]").each(function(x) {
if (i === x) {
var str = "较慢";
if (ping < 300) {
$(this).css("color", "green");
str = "极快";
}
if (ping > 300 && ping < 500) {
$(this).css("color", "#00FF00");
str = "较快";
}
if (ping > 500) {
$(this).css("color", "#666666");
}
$(this).text("" + str + "" + "(" + ping * 1 + "ms)");
}
});
}
$(function() {
$("span[speed]").each(function(i) {
var sortid = $(this).attr("speed");
var self = $(this);
self.append('<img src="' + sortid + '?' + Math.random() +
'" width="1" height="1" style="display:none" onerror=test(' + i + ') >');
});
});
</script>