(#每日一点点)day3-JavaScript(一) 用法
JavaScript用法
- JavaScript 是脚本语言,可插入 HTML 页面,可由所有的现代浏览器执行。
- JavaScript写入的位置:
(1). 在 HTML 页面中插入JavaScript时,需要使用script标签。可以写在head标签中,也可以写在body标签中。
(2). 将脚本写在外部文件中,文件扩展名是 .js ,并使用script标签的src属性引用到 HTML 页面中。注意,外部文件中只写js语句,不能出现script标签。
<body>
<script src="order.js"></script>
<div id="hello">你好</div>
<button type="button" onclick="myFunction()">点击这里</button>
</body>
/*外部文件中的代码片段*/
function myFunction()
{
document.getElementById("hello").innerHTML="Hello!";
}