使用 jQuery 在链接上重新触发点击事件 [英] re-firing a click event on a link with jQuery
问题描述
我有一个页面 (asp.net),我可以在其中捕获链接的点击事件.然后我做一些脏检查并向用户展示一个对话框,
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;
});
});
是否要取消更改 Yes/No 等
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;
附注.输"
这篇关于使用 jQuery 在链接上重新触发点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!