Javascript miscellanea -display data real time, using window.status
更新時(shí)間:2007年01月09日 00:00:00 作者:
<script type="text/javascript">
//<![CDATA[
function fstatus() {
for (var i=0; i<100000; i++) {
window.status = "now process is \"" +i+ "\"";
}
}
function finnerHtml() {
for (var i=0; i<1000; i++) {
document.getElementById("demo").innerHTML = "now process is \"" +i+ "\"";
}
}
//]]>
</script>
<input type="button" onclick="fstatus()" value="test status"/>
<input type="button" onclick="finnerHtml()" value="test innerHTML"/>
<div id="demo"></div>
In the above example,one have a loop and display it real time use innerHTML property, another is use window.status.
However, the window.status in real time that perfect display the loop digit, but the innerHTML property is not.
Just display result digit: now process is "999".
And how to using innerHTML display real time data? can but use window.setTimeout, or window.setInterval method, like this:
var cnt=0;
function finnerHtml() {
if (cnt++>=1000) return;
document.getElementById("demo").innerText = "now process is \"" +cnt+ "\"";
window.setTimeout(finnerHtml,10)
}
But, it's no convenient. the display speed is not well, and we must control something.
e.g.
setTimeout variables, when it completely.
So, I propose winodw.status to replace innerHTML property when display in real time.
//<![CDATA[
function fstatus() {
for (var i=0; i<100000; i++) {
window.status = "now process is \"" +i+ "\"";
}
}
function finnerHtml() {
for (var i=0; i<1000; i++) {
document.getElementById("demo").innerHTML = "now process is \"" +i+ "\"";
}
}
//]]>
</script>
<input type="button" onclick="fstatus()" value="test status"/>
<input type="button" onclick="finnerHtml()" value="test innerHTML"/>
<div id="demo"></div>
In the above example,one have a loop and display it real time use innerHTML property, another is use window.status.
However, the window.status in real time that perfect display the loop digit, but the innerHTML property is not.
Just display result digit: now process is "999".
And how to using innerHTML display real time data? can but use window.setTimeout, or window.setInterval method, like this:
var cnt=0;
function finnerHtml() {
if (cnt++>=1000) return;
document.getElementById("demo").innerText = "now process is \"" +cnt+ "\"";
window.setTimeout(finnerHtml,10)
}
But, it's no convenient. the display speed is not well, and we must control something.
e.g.
setTimeout variables, when it completely.
So, I propose winodw.status to replace innerHTML property when display in real time.
相關(guān)文章
點(diǎn)擊按鈕后 文本框變?yōu)镾elect下拉列表框
在招聘類的網(wǎng)站會(huì)見到不少類似效果,文本框中最開始默認(rèn)的是文字 ,如果點(diǎn)擊更改這類的按鈕文本框就變成了一個(gè)可以選擇的Select下拉列表框,挺有創(chuàng)意,以下是代碼,復(fù)制即可用啦。2009-09-09
Javascript miscellanea -display data real time, using window
Javascript miscellanea -display data real time, using window.status...2007-01-01
firefox(火狐)和ie瀏覽器禁止右鍵和禁止復(fù)制的代碼
多瀏覽器兼容的禁止右鍵和禁止復(fù)制的代碼。2009-09-09
javascript 仿開心網(wǎng)好友印象功能(點(diǎn)擊文字彈出印象框)
這是仿開心網(wǎng)的好友印象添加功能,在輸入框里提交印象詞后,即可顯示在網(wǎng)頁上,點(diǎn)擊文字彈出印象評(píng)語提示框。想用的朋友最好在重新美化一下,我覺得還是不錯(cuò)的。2009-12-12

