jQuery的on方法和bind绑定多个事件

it2026-09-25  15

on方法是官方推荐使用的方法比较新

1. on:

多个事件绑定同一个函数

$(document).ready(function(){

  $("p").on("mouseover mouseout",function(){

    $("p").toggleClass("intro");

  });

});

多个事件绑定不同函数

$(document).ready(function(){

  $("p").on({

    mouseover:function(){$("body").css("background-color","lightgray");},  

    mouseout:function(){$("body").css("background-color","lightblue");}, 

    click:function(){$("body").css("background-color","yellow");}  

  });

});

2. bind:

$("#registerBtn").bind("click dblclick", function(){            location.href = "register.html";        });

转载于:https://www.cnblogs.com/YingYue/p/4627637.html

相关资源:jQuery使用bind函数实现绑定多个事件的方法
最新回复(0)