这个好像是没有办法了,因为innerHTML中的字符串显示在窗口中时的过程并不是js引擎来处理而是HTML解析器(姑且这样认为,可能不叫HTML解析器,但是反正不是js引擎) 干的活,从这个意义上说当js引擎将这段字符串传给了HTML解析器后就认为这个语句已经执行完毕,马上就执行下面的alert语句,但是实际上HTML解析器显示出来是需要时间的。
所以这个动作就好像是两个进程在同时工作,就看哪个执行快了。笨些的方法就是让alert延时。
所以这个动作就好像是两个进程在同时工作,就看哪个执行快了。笨些的方法就是让alert延时。
<script language="javascript" type="text/javascript">
function t()
{
window.setTimeout('modual()', 2000);
} function modual()
{
document.getElementById('t').innerHTML = "<input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3><input type='hidden' id='flag' value='flag'><h3 style='color:green;'>Hello world!</h3>";
alert('OK');
}</script>
</HEAD><BODY>
<input type="button" value="Go!" onclick="t();">
<span id='t'></span>
</BODY>
</HTML>