在我的客户端页面上,我想在每次用户点击某些内容时执行我的功能。函数将此元素标记名称发送到数据库。为避免覆盖客户端页面单击事件处理程序,我使用mousedown
。我的想法:
jQuery('body').on('mousedown', function(event){
var that = event.target,
thatTag = event.target.nodeName;
jQuery.get(
"http://example.com",
{ parameter: thatTag },
function() {
//It hasn't time to execute, because mouseup is auto executed and click action change location (if I click anchor)
}
);
});
那么,在我的GET操作完成之前,暂停/阻止mouseup
/ click
是否有任何选项?
答案 0 :(得分:0)
首次执行时,您需要使用.off取消绑定mousedown
处理程序,然后在.get
函数完成时再次重新绑定:
$(function() {
// On page load, bind the first instance of the event
$("body").on("mousedown", handleMouseDown);
});
function handleMouseDown(event) {
// Detach the event so that is isn't handled again until the .get finishes
$("body").off("mousedown", handleMouseDown);
var that = event.target,
thatTag = event.target.nodeName;
jQuery.get(
"http://example.com",
{ parameter: thatTag },
function() {
// Re-attach the event now that the .get has finished
$("body").on("mousedown", handleMouseDown);
}
);
}