<html>
<head>
<script>
//生成文本
document.write('子为政,焉用杀?');
//生成普通文本和标签
document.write('<span>朝闻道,夕死可矣!</span>');
//body初始化
function message() {
window.alert('我从未见过,如此好学如好色之人!');
}
</script>
</head>
<body onload="message()">
<script type="text/javascript">
//JavaScript是所有现代浏览器以及 HTML5 中的默认脚本语言。
//所以不需要写type="text/javascript"
window.alert('道可道,非常道!');
</script>
</body>
<footer>
<span>
如果我们在script标签内部引用了某个DOM元素,那么必须等这个
DOM元素创建完毕。因此,如果script部分安在dom之前,但是script
中又引用了dom,在这种情况下,就会发生引用错误。
</span>
</footer>
</html>
<head>
<script>
//生成文本
document.write('子为政,焉用杀?');
//生成普通文本和标签
document.write('<span>朝闻道,夕死可矣!</span>');
//body初始化
function message() {
window.alert('我从未见过,如此好学如好色之人!');
}
</script>
</head>
<body onload="message()">
<script type="text/javascript">
//JavaScript是所有现代浏览器以及 HTML5 中的默认脚本语言。
//所以不需要写type="text/javascript"
window.alert('道可道,非常道!');
</script>
</body>
<footer>
<span>
如果我们在script标签内部引用了某个DOM元素,那么必须等这个
DOM元素创建完毕。因此,如果script部分安在dom之前,但是script
中又引用了dom,在这种情况下,就会发生引用错误。
</span>
</footer>
</html>