代码1:<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试</title>
</head>
<body>
</body>
<script type="text/javascript"  src="test.js">
</html>test.js 文件边的代码是:document.write("<h1>你好</h1>")当打开网页查看源代码的时候是出现的是<script type="text/javascript"  src="test.js"> 而不是<h1>你好</h1>  , 求助下各位js高手怎么才能才实现在查看源代码的时候变成js里边的<h1>你好</h1>?  小弟菜鸟一个如果可以希望能写个实例,多谢了!!

解决方案 »

  1.   

    js生成的东西源代码是看不到的。源代码看到的是服务器生成的html.所以你的要求做不到。
      

  2.   


    让“查看源代码”里出现是法
    可以用JS取alert( document.documentElement.innerHTML );
      

  3.   

    = =
    把<script>标签移到body中试试
      

  4.   

    用firefox的friebug或者chrome的开发者工具(浏览器中按F12)查看就能看到了,直接查看源代码看到的是原始文件,看不到js执行后的结果。
      

  5.   

    按照楼上说的 你引入的script标签没有闭合 javascript引用都是<script></script>这样的<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>测试</title>
    </head>
    <body>
    </body>
    <script type="text/javascript"  src="test.js"></script>
    </html>