//=====在网站找到了解决方法=====//动态生成的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();