js代码编写的位置:
1.在html中用script标签来写
2.在button中用onclick属性来写
3.在a标签中用href来写
4.可以创建js文件,然后用script标签引用
hello world显示方案:
1.按钮,a标签和script标签:
<button onclick="alert('hello world')"> button</button>
<a href="javascript:alert('hello world');">link</a>
<script>alert("hello world"); </script>
2.引用js文件:
<script src="./js.js"></script>
js文件的代码:
alert("hello world");
注:
- script标签一旦引入外部文件,就不能编写代码了,即使写了浏览器也会自动忽略。
如果需要在创建一个script代码。 - alert的作用:控制浏览器弹出一个警告对话框