如何将多个事件绑定(bind)到同一个函数。我希望 click 和 touchstart 也能做到这一点。然后我想要第二个鼠标悬停功能。我想使用这种设置:
$(document).on({
click: function (event) {
// I want this: click, touchstart: function (event) {
event.preventDefault();
// do something
},
mouseover: function (event) {
event.preventDefault();
// do something
}
}, '.link');
最佳答案
您可以将事件组合在一个 .on()
中并使用空格:
$(document).on('click touchstart', function(e) {
// this will be called on click as well as touchstart
});
关于jquery - 将多个事件绑定(bind)到同一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17425311/