## 事件绑定
### 1.bind()方法
结构:`bind(事件类型,回调函数)`;
~~~javascript
<input type="button" value="点我">
$('input[type=button]').bind('click',function(){
lg('hello world');
});
~~~
### 2.on()方法
on()方法结构和使用与bind()没有任何区别。
> 新版本的jQuery里面都是使用on()方法,bind()方法已经不再使用了。
~~~javascript
<input type="button" value="点我">
$('input[type=button]').bind('click',function(){
lg('hello world');
});
~~~
### 3.阻止冒泡
使用事件对象 event 的方法`stopPropagation();`
~~~javascript
$('input[type=button],div,body,html').on('click',function(event){
lg('click');
event.stopPropagation();
});
~~~
### 4.绑定多个事件
on()方法中可以使用类似JSON结构进行处理。
~~~javascript
$('input[type=button]').on({
hover:function(){
$(this).css('color','red');
},
mouseout:function(){
$(this).css('color','#fff');
},
click:function(){
alert('aaa');
}
});
~~~
### 5.事件解绑
使用unbind()方法解绑事件
~~~javascript
$('input[type=button]').on('click',function(){
lg('click');
$(this).unbind('click');
});
~~~