控制器方法
public function autoDemo(){ $this->display(); for ($i=0; $i < 50; $i++) { sleep(3); show_msg($i.'*3秒过去了...','green'); } }
输出函数
function show_msg($msg, $class = ''){ echo "<script type=\"text/javascript\">showmsg(\"{$msg}\", \"{$class}\")</script>"; flush(); ob_flush();}
模板
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Document</title></head><body> <div id="show-list" class="install-database"> </div> <script type="text/javascript"> var list = document.getElementById('show-list'); function showmsg(msg, classname){ var li = document.createElement('p'); li.innerHTML = msg; classname && li.setAttribute('class', classname); list.appendChild(li); document.scrollTop += 30; } </script></body></html>