网页不能正常运行

chair128 2010-11-26 07:40:39
各位大虾:
晚上好!
小弟刚学习做网页,写了一个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>
...全文
114 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
myqq155120699 2010-11-27
  • 打赏
  • 举报
回复
不能正常运行的原因可能是:你的文件含用不可见的特殊字符。
chair128 2010-11-26
  • 打赏
  • 举报
回复
我找到解决方法了,刚才我将原htm页的所有代码copy到新建的.txt文档,改名保存,用IE8打开新就正常了!但原htm无论我怎么改名就是不运行,不知道啥原因呢。
逍遥庄主 2010-11-26
  • 打赏
  • 举报
回复
IE8 测试 没有问题 也看不出哪有什么错误的地方
chair128 2010-11-26
  • 打赏
  • 举报
回复
补充:我其它的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编码是简体中文,自动选择也试了。
hch126163 2010-11-26
  • 打赏
  • 举报
回复
<!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>
chair128 2010-11-26
  • 打赏
  • 举报
回复
还是不行啊!不知什么原因?
我已删掉了:
<?xml version="1.0" encoding="UTF-8" ?> 这一句,
打开后,不行。
然后又删掉了:
xml:lang="en" lang="en" 这一句,
再重新打开,还是不行。
请各位高手帮忙。是不是IE8设置问题。
孟子E章 2010-11-26
  • 打赏
  • 举报
回复
我IE8测试没问题。你的文件需要存成htm,最好去掉
<?xml version="1.0" encoding="UTF-8" ?>

另外,注意文件的编码

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧