jquery同一标签绑定多个事件的几种方式
①$(document).ready(function(){
$("button").bind({
click:function(){},
mouseover:function(){},
mouseout:function(){};
});
});
②$(function(){
$('#btn').bind("click",function(){
}),bind("click",function(){
}),bind("click",function(){
});
});
③为元素一次性绑定多个事件类型
$(function(){
$("div").bind("mouseover mouseout",function(){
});
});
// 前进
$('.layui-header').find('.forward-btn').bind({
click:function() {
window.history.forward();
},
mouseover:function() {
layer.tips('前进', $(this), {
tips: [1, '#3595CC'],
time: 4000
});
},
mouseout:function() {
layer.closeAll();
}
});
// 后退
$('.layui-header').find('.back-btn').bind({
click:function() {
window.history.back();
},
mouseover:function() {
layer.tips('后退', $(this), {
tips: [1, '#3595CC'],
time: 4000
});
},
mouseout:function() {
layer.closeAll();
}
});
// 刷新
$('.layui-header').find('.refresh-btn').bind({
click : function() {
window.location.reload();
},
mouseover:function() {
layer.tips('刷新', $(this), {
tips: [1, '#3595CC'],
time: 4000
});
},
mouseout:function() {
layer.closeAll();
}
});
本文详细介绍了使用jQuery库为同一HTML元素绑定多个事件的方法,包括click、mouseover和mouseout等常见事件,展示了如何通过bind方法一次绑定多种事件,提高前端开发效率。

445

被折叠的 条评论
为什么被折叠?



