Javascript miscellanea -display data real time, using window.status

2018-09-24 21:44

阅读:564

  <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.


评论


亲,登录后才可以留言!