有人可以回答我为什么会出现这个问题吗?
使用以下代码我的网站只能在 Chrome 中运行,在 IE7/8 和 Firefox 上只显示背景:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Site Title</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js" />
<script type="text/javascript" src="js/functions.js" />
</head>
...
此代码适用于 Chrome、IE7/8 和 Firefox:
<!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" lang="pt-br" xml:lang="pt-br">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CSite Title</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/functions.js"></script>
</head>
...
查看在 Firebug 中不起作用的代码,我看到文件“functions.js”没有被调用,我不明白,为什么不能使用“<script />
”和“<script></script>
” “有效吗?
最佳答案
来自这张票 ( Why don't self-closing script tags work? )
(请注意,在引用的票证中,接受的答案实际上并不正确)
Note that IE does not support XHTML parsing. Even if you use an XML declaration and/or an XHTML doctype, IE still parses the document as plain HTML. And in plain HTML, the self-closing syntax is not supported. The trailing slash is just ignored, you have to use an explicit closing tag.
Even browsers with support for XHTML parsing will still parse the document as HTML unless you serve the document with a xml mime type. But in that case IE will not display the document at all!
关于javascript - 在HTML中添加脚本JS问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1582219/