javaScript 逾時與間歇掉用,javascript間歇
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>js的間歇與逾時調用</title></head><body><font id="time"></font></body></html><script type="text/javascript">//注意需要讓當前的dom載入完全之後,再執行js代碼var parent = document.getElementById('time');var time = new Date();var child = document.createTextNode('當前time:'+time.toLocaleString());parent.appendChild(child);//利用setInterval設定相隔一秒更新時間var id = setInterval(function(){parent.removeChild(parent.firstChild);var child = document.createTextNode('當前time:'+(new Date).toLocaleString());parent.appendChild(child);},1000);//利用setTimeout()延遲某代碼的執行,同時利用clearTimeout()清除執行計畫//1分鐘後取消時間的更新setTimeout(function(){//取消時間更新clearTimeout(id);alert('現在可以開始搶購小米手機了');},1000*60);</script>
這段JavaScript的逾時功可以代碼怎運行不了?
function Update()
{
counter++;
document.form1.input1.value="The counter is now at " + counter;
ID=window.setTimeout("Update();"2000);
}
裡面的ID=window.setTimeout("Update();"2000);少了逗號,看見沒?你以後用firefox來偵錯工具吧,再裝一個firebug外掛程式,這類語法錯誤你還沒開始運行它就已經提示你了。大大縮短你的開發時間。
怎讓javascript在xmlHTTP時 操作逾時?
用戶端檔案,請修改檔案名稱為:test_2.htm
<html>
<body>
xmlhttp非同步例子:
URL: <input name=a type=textbox value="test_s.asp" style="width:600px" >
<input onclick= "getXML()" type= "button" value= "得到原始碼">
<input name=geti type=textbox value="10000">
<input onclick= "if(xh && xh.responseText) {alert(xh.responseText);oDiv.innerHTML=xh.responseText} " type= "button" value= "顯示原始碼 " >
<div id=m style="display:none"></div>
<script language=javascript>
var oDiv
var xh
function getXML()
{
oDiv = document.all.m;
oDiv.innerHTML = "正在裝載欄目資料,請稍侯....... ";
oDiv.style.display = "";
xh = new ActiveXObject("Microsoft.XMLHTTP")
xh.onreadystatechange = getReady;
xh.open("POST",a.value + "?geti=" + geti.value,true);
//alert("geti=" + geti.value);
xh.send();
}
function getReady()
{
if(xh.readyState==4)
{
if(xh.status==200)
{
oDiv.innerHTML = xh.responseText;
oDiv.innerHTML = oDiv.innerHTML + "load over"
}
else
{
oDiv.innerHTML = "抱歉,裝載資料失敗。原因: " + xh.statusText
// 我測試了,一旦已耗用時間過長會出現:抱歉,裝載資料失敗。原因: Internal Server Er......餘下全文>>