javaScript 逾時與間歇掉用,javascript間歇

來源:互聯網
上載者:User

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......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.