页面内嵌:
<script></scriptt>
外部引入:
<script scr=""></script>
基本语法:
1,命名函数表达式:
var test = function a(b, c) {
var d = b + c
document.write(d);
}
2,匿名函数表达式:
var test = function (b, c) {
var d = b + c
document.write(d);
}
3,事件:
<div style="width:100px;height:100px;background-color:blue;"></div>
<script type="text/javascript">
var div=document.getElementsByTagName("div")[0];
//一种
div.onclick = function () {
this.style.background-color=red;
}
//另一种
div.addEventListener("click",function () {this.style.background-color=red;},false);
//div.onclik 对div容器内容鼠标点击触发事件.