jquery 一个对象绑定多个事件
<html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> #app { width: 100px; height: 100px; background-color: #eee; } #app p{ height: 20px; background: #000000; } </style> </head> <body> <div id="app"> <p></p> </div> </body> </html>
1. on()方法
$("#app").on("click mouseover", function() {
console.log(1)
});
2.bind()方法
$("#app").bind("click mouseover", function() {
console.log(1)
});
3.delegate()方法
$("#app").delegate("p", "click mouseover", function() {
console.log(1)
});