【发布时间】:2010-10-24 20:47:37
【问题描述】:
我在单独的 Sample.js 文件中有这个脚本:
function MyPrint(text)
{
document.write(text);
}
我有以下 HTML 页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Silly example</title>
</head>
<body>
<div>
<script type="text/javascript" src="JavaScript/Sample.js">
MyPrint("Hello silly world!");
</script>
</div>
</body>
</html>
最终的结果是文本“Hello silly world!”未打印在页面上。我应该怎么做才能完成这项工作?如果可能的话,我不希望将脚本标签移到头部。谢谢。
【问题讨论】:
-
在哪个浏览器中?这就是 1990 年代遗留脚本的问题。
-
从脚本标签中删除 src 并放入一个新的。
标签: javascript