写html文件内
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script type="text/javascript"></script>
</head>
<body>
<!--
JavaScript除了写在<script type="text/javascript"></script>外还可以写在外部文本和一些标签中
这些标签只要有有链接的标签和有onclick属性的按钮
注意在alert的弹窗口未被点击时,代码会停留在alert这一行里
Script标签可以卸载body里面,而且会先执行,不论前面是否有其他的h5代码
-->
<a href="javascript:alert('写在标签中1');">示范</a>
<a href="javascript:document.write('写在标签中2');">示范</a>
<a href="javascript:console.log('写在标签中3');">示范</a>
<button onClick="javascript:alert('写在标签中4');">示范</button>
<button onClick="javascript:document.write('写在标签中5');">示范</button>
<button onClick="javascript:console.log('写在标签中6');">示范</button>
<p>------------------------------分隔符-----------------------</p>
<p>这是body里面的p标签</p>
<!--
在浏览器的审查或检查中,会发现代码里面多了一行p标签,
这个标签是通过JavaScript的document.write写出来的
一对双引号之间不能加一对双引号,一对单引号里也不知在加一对单引号
在字符串之间用\表示在为了美观清晰,让代码里换一行继续写,并不是文字效果换行
-->
<Script type="text/javascript">
document.write("<p>这是JavaScript里的p标签</p>");
document.write("换\
行");
// document.write("没换
// 行");//没加\直接回车换行这种情况会报错
</script>
</body>
</html>
写作html文件外的js文件
<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="../js/写在外部文本中.js">
alert("这是内部");
</script>
</head>
<body>
<!--如果已经引用外部的JavaScript代码,那内部就不能在编写JavaScript,即使编写浏览器也会忽略-->
</body>
</html>
// JavaScript Document
alert("写在标签中1");
document.write("写在标签中2");
console.log("写在标签中3");