测试站点的链接速度

<script>
	// 测试站点的连接速度
	var t = 0;
	
	var btn;
	var st,et;
	function test(e) {
		st = new Date().getTime();
		btn = e;
		urlForm.firstChild.rows[0].cells[3].innerHTML = "正在测试..."
		e.disabled = true;
		document.getElementById("img").src = document.getElementById("urlText").value + "/" + Math.random();
		document.getElementById("img").onerror = list;
		//alert(document.getElementById("img").src);
	}
	
	function list() {
		et = new Date().getTime();
		if ((et - st) > 5000) {
			urlForm.timeTxt.value = "链接超时";
		}
		else {
			urlForm.timeTxt.value = (et - st) / 1000 + "s";
		}
		urlForm.firstChild.rows[0].cells[3].innerHTML = "测试完毕--" + new Date().toLocaleString();
		btn.disabled = false;
	}
</script>
<body>
	<form id="urlForm">
		<table>
			<tr>
				<td><input type="text" id="timeTxt"></td>
				<td><input type="text" id="urlText" value="http://www.baidu.com"></td>
				<td><input type="button" id="testBtn" value="Test" onclick="test(this);">
					<input type="button" id="go" value="GO" onclick="javascript:window.open(urlText.value);">
					<img id="img" width=1 height=1></td>
				<td></td>
			</tr>
			<tr><td id="r"></td></tr>
		</table>
	</form>
</body>

 

你可能感兴趣的:(JavaScript)