Javascript miscellanea -display data real time, using window.status
2018-09-24 21:44
<scripttype=text/javascript>
//<![CDATA[
functionfstatus(){
for(vari=0;i<100000;i++){
window.status=nowprocessis\+i+\;
}
}
functionfinnerHtml(){
for(vari=0;i<1000;i++){
}
}
//]]>
</script>
<inputtype=buttononclick=fstatus()value=teststatus/>
<inputtype=buttononclick=finnerHtml()value=testinnerHTML/>
<divid=demo></div>
Intheaboveexample,onehavealoopanddisplayitrealtimeuseinnerHTMLproperty,anotherisusewindow.status.
However,thewindow.statusinrealtimethatperfectdisplaytheloopdigit,buttheinnerHTMLpropertyisnot.
Justdisplayresultdigit:nowprocessis999.
AndhowtousinginnerHTMLdisplayrealtimedata?canbutusewindow.setTimeout,orwindow.setIntervalmethod,likethis:
varcnt=0;
functionfinnerHtml(){
if(cnt++>=1000)return;
document.getElementById(demo).innerText=nowprocessis\+cnt+\;
window.setTimeout(finnerHtml,10)
}
But,itsnoconvenient.thedisplayspeedisnotwell,andwemustcontrolsomething.
e.g.
setTimeoutvariables,whenitcompletely.
So,Iproposewinodw.statustoreplaceinnerHTMLpropertywhendisplayinrealtime.
文章标题:Javascript miscellanea -display data real time, using window.status
文章链接:http://soscw.com/index.php/essay/17732.html