on绑定的四种方式!
HTML
<button>点击</button>
<p>on绑定事件</p>
<p>点击</p>
<p>移入</p>
1.使用on进行单个事件绑定
$("button").on("click",function(){
alert($("p").text())
});
2.使用on同时为多个事件,绑定同一函数
$("button").on("mouseover click",function(){
alert($("p").text());
})
3.使用on进行多事件和多函数绑定
$("button").on({click:function(){
alert($("p:eq(1)").text())
},
mouseover:function(){
alert($("p:eq(2)").text());
}
});
4.调用函数时,传入自定义参数
$("button").on("click",{name:"jianghao"},function(event){//使用event.data.属性名 找到传入的参数
alert(event.data.name);
})