当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Javascript miscellanea -display data real time, using window.status

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

2019年08月02日  | 移动技术网IT编程  | 我要评论

亚洲最大火车站,朱永博,华南理工大学广州学院教务管理系统

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网