js 的作用就是 让页面产生动画效果, 让用户体验更好. js中有两种事件注册方式 ,可以让页面产生动画效果
1.命名式函数 :
<标签 on 事件=“函数()”>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function button(){
document.write("你已经成功点击了我")
}
</script>
</head>
<body>
<div><button value="点点我" οnclick="button()">点点我</button></div>
</body>
</html>
2.匿名式函数绑定:
对象.on事件=function(){ }
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="button" value="点点我" id="button">
<script type="text/javascript">
document.getElementById("button").onclick = function () {
alert("你已经成功点击了我");
}
</script>
</body>
</html>
匿名式函数绑定有一点需要注意 那就是script 位置不要乱放 ,要放在input标签的下面
这里涉及到了 局部变量 还有 全局变量的 区别 ;