js的三种书写位置
1.行内式
代码如下(示例):
<body
>
<input type
="button" value
="点击会出现弹窗" onclick
="alert('行内式js')">
</body
>
onclick 为鼠标单击事件,后续会有更多事件讲解,先做了解
2.内嵌式的js
代码如下(示例):
<head
>
<meta charset
="UTF-8">
<title
>Title
</title
>
<script
>
alert('内嵌式的js');
</script
>
</head
>
在head标签内 添加script标签和想要执行的事件方法
3.外部的js
代码如下(示例):
将方法写在外部js文件中 文件名 test.js
alert('外部的js');
<head
>
<meta charset
="UTF-8">
<title
>Title
</title
>
<script src
="test.js"></script
>
</head
>
总结
纪念第一次写博客 嘻嘻 适合有点基础的小朋友跟着一起学 零基础小白请忽略