一、 写在行内
<input type="button" value="按钮" onclick="alert('Hello World')" />
二、写在script标签中
<head>
<script>
alert('Hello World!');
</script>
</head>
三、 写在外部js文件中,在页面引入
<script src="main.js"></script>
-
注意点
引用外部 js文件的 script标签中不可以写JavaScript代码