在jQuery链接上重新点击一个点击事件 [英] re-firing a click event on a link with jQuery
问题描述
我有一个页面(asp.net),我捕获链接的点击事件。
i然后做一些脏的检查,并向用户提出一个对话框,
i've got a page (asp.net) where I trap the click event of a link. i then do some dirty checking and present a dialog to the user,
$(function() {
var clickedLink;
$('.checkdirty').click(function(event) {
if(isDirty == false){
return true;
}
clickedLink = $(this);
$('#dirtysave-dialog').dialog('open');
return false;
});
});
是否要松动您的更改是/否等。
do you want to loose your changes Yes/No etc.
$('#dirtysave-dialog').dialog({ bgiframe: true, autoOpen: false,
height: 125, width: 425, modal: true,
title: "You have unsaved changes, do you want to continue and loose changes?!!",
buttons: {
"Yes": function() {
isDirty = false;
$(this).dialog("close");
$(clickedLink).click();
},
"No": function() {
$(this).dialog("close");
}
},
open: function(type, data) {
$(this).parent().appendTo("form");
}
});
如果他们点击是,我然后清除isDirty标志,并点击链接。这返回到点击事件处理程序,检查
if they click yes i then clear the isDirty flag and call click on the link. this goes back in to the click event handler, does the check
if(isDirty == false){
return true;
}
返回true,但事件永远不会发生....
returns true but the event never happens....
我需要手动单击该链接才能触发。
i need to click the link again manually for it to fire.
任何想法?
推荐答案
.click()
仅触发 onclick
的事件处理程序,实际上并不会使链接发生的默认操作。可能最快的方法只是手动执行:
.click()
only fires the event handlers for onclick
, it doesn't actually make the default action of following the link happen. Probably the quickest method is just to do that manually:
window.location= clickedLink.href;
PS。 输
这篇关于在jQuery链接上重新点击一个点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!