各位大虾:
    晚上好!
    小弟刚学习做网页,写了一个htm页在VS2008中调试成功,但单独用IE8打开时,只显示了标题,就运行不了下面的javascrpt脚本,查了好久,不知道是什么原因?代码如下:<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html
  PUBLIC "-//W3C//DTD THTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>JavaScript DOMColor Properties</title>
</head>
<body>
    <h3>The color properties</h3>     // 只运行到这行就结束了    <script type="text/javascript">
  <!--
    document.write("<br>")    document.write("<h4>Background Color</h4>")
    document.write(document.bgColor)
    document.write("<br>")    document.write("<h4>Old Foreground Color</h4>")
    document.write(document.fgColor)
    document.write("<br>")
    
    document.write("<h4>ActiveLink Color</h4>")
    document.write(document.alinkColor)
    document.write("<br>")    document.write("<h4>UnvisitedLink Color</h4>")
    document.write(document.linkColor)
    document.write("<br>")    document.write("<h4>Visited Link Color</h4>")
    document.write(document.vlinkColor)
    document.write("<br>")    alert("Changing color")
    document.fgColor="red"
    document.write("<h4>New Foreground Color</h4>")
    document.write(document.fgColor)
    document.write("<br>")
  // -->
    </script></body>
</html>

解决方案 »

  1.   

    我IE8测试没问题。你的文件需要存成htm,最好去掉
    <?xml version="1.0" encoding="UTF-8" ?>另外,注意文件的编码
      

  2.   

    还是不行啊!不知什么原因?
    我已删掉了:
    <?xml version="1.0" encoding="UTF-8" ?> 这一句,
    打开后,不行。
    然后又删掉了:
     xml:lang="en" lang="en"  这一句,
    再重新打开,还是不行。
    请各位高手帮忙。是不是IE8设置问题。
      

  3.   

    <!DOCTYPE html
      PUBLIC "-//W3C//DTD THTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
      <title>JavaScript DOMColor Properties</title>
    </head>
    <body>
      <h3>The color properties</h3> // 只运行到这行就结束了  <script type="text/javascript">
      <!--
      document.write("<br>")  document.write("<h4>Background Color</h4>")
      document.write(document.bgColor)
      document.write("<br>")  document.write("<h4>Old Foreground Color</h4>")
      document.write(document.fgColor)
      document.write("<br>")
       
      document.write("<h4>ActiveLink Color</h4>")
      document.write(document.alinkColor)
      document.write("<br>")  document.write("<h4>UnvisitedLink Color</h4>")
      document.write(document.linkColor)
      document.write("<br>")  document.write("<h4>Visited Link Color</h4>")
      document.write(document.vlinkColor)
      document.write("<br>")  alert("Changing color")
      document.fgColor="red"
      document.write("<h4>New Foreground Color</h4>")
      document.write(document.fgColor)
      document.write("<br>")
      // -->
      </script></body>
    </html>
      

  4.   

    补充:我其它的javascript网页是可以用IE8正常运行的,如这个:<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
      <title>Mouse Overs</title>
    </head>
    <body>
      <h3 onmouseover="this.style.fontSize='24pt'" onmouseout="this.style.fontSize='14pt'">Mouse Overs</h3>
      
      <p>When it comes to rollovers, Netscape browsers are a little weak. The second image rollover works in Netscape 3.0+.
        Gecko promises to be better.</p>
        
      <a href="" onmouseover="m_over()" onmouseout="m_out()"><img alt="face" src="face.gif" border="0" /></a>
      
      <script>
      <!--
        function m_over() {
          document.images[0].src="face2.gif";
        }
        function m_out() {
          document.images[0].src="face.gif";
        }
      // -->
      </script>
    </body>
    </html>可以正常显示两个gif. IE8编码是简体中文,自动选择也试了。
      

  5.   

    我找到解决方法了,刚才我将原htm页的所有代码copy到新建的.txt文档,改名保存,用IE8打开新就正常了!但原htm无论我怎么改名就是不运行,不知道啥原因呢。