[英]Interrupt all mousedown events to simulate like a mouse click
I want to trigger click event on a element when mousedown occurs. 我想在发生mousedown时触发元素上的click事件。 Also, I want to enable this feature for all elements in a html page. 另外,我想为html页面中的所有元素启用此功能。
Is it possible with jQuery on Chrome ? Chrome上的jQuery是否可能?
Here's my first attempt; 这是我的第一次尝试;
$.fn.mousedown = function (onclick) {
this.bind("click", function (e) { onclick.call(this, e); });
return this;
};
But this mousedown elements fired after click occurs. 但是,单击发生后会触发此mousedown元素。
$(document).on('mousedown', function (e) { $(e.target).trigger('click') })
I'm not sure though for what this should be useful. 我不确定这对什么有用。
To prevent the second click (which is the normal click) you have to do some extra work 为了防止第二次点击(这是正常的点击),您必须做一些额外的工作
$(document).on('mousedown', function (e) {
$(e.target).trigger('click').once('click', function (e) {
e.preventDefault();
e.stopPropagation();
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.