//=====在網站找到了解決方法=====//動態生成的html代碼var htmlCode = '<html><head><title>代碼</title></head><body><div style=「width:500px;height:300px;border:1px solid #dbdbdb;」>這裏是代碼</div></body></html>';//打開瀏覽器窗口,並運行html代碼var codeWin = window.open("", "代碼預覽", "status=no,menuber=yes,toolbar=no,height=500,width=800"); codeWin.document.open(); codeWin.document.write(htmlCode); codeWin.document.close();