在js中加一段
window.onload = function(){
alert('aaa');
}可否~

解决方案 »

  1.   

    整体来说是你的思路不对,没有理解onload事件的执行时机。一般来说document.write出来的代码中的onload是不可能被触发的,但是你可以作为一个文档open(作为当前文档的frame)然后再write。<HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function init()
    {
    test.document.open();
    test.document.write("<html><head></head><body onload='alert(11)'>iframe</body></html>");
    test.document.close();
    }
    //-->
    </SCRIPT>
    </HEAD>
    <BODY onload="init()">
    <iframe name="test"/>
    </BODY>
    </HTML>