javascript的一些注意点

警告

请使用 document.write() 仅仅向文档输出写内容。

如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖:

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>

<p>My First Paragraph.</p>

<button onclick="myFunction()">点击这里</button>

<script>
function myFunction()
{
document.write("糟糕!文档消失了。");
}
</script>

</body>
</html>

 

外部引用

在 <head> 或 <body> 中引用脚本文件都是可以的。实际运行效果与您在 <script> 标签中编写脚本完全一致。

提示:外部脚本不能包含 <script> 标签。

<script src="xxxxx.js"></script>

 

posted @ 2013-08-30 13:26  风林火山09  阅读(191)  评论(0编辑  收藏  举报