<?php function script_callback($script) { return '<mce:script type="text/javascript"><!-- '.$script.' // --></mce:script>'; } function delayHello($seconds) { $i=$seconds*1000; ob_start("script_callback"); echo "setTimeout('alert(/"hello world/")',$i)"; ob_end_flush(); } echo "Delay Hello 5 seconds<br>"; delayHello(5); echo "Delay another 10 seconds"; delayHello(10); ?> 采用输出缓存自动为js片段添加script标记