再发射使用jQuery的链接上的click事件 [英] re-firing a click event on a link with jQuery

查看:252
本文介绍了再发射使用jQuery的链接上的click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页(asp.net),我的陷阱链接的点击事件。
然后我做一些肮脏的检查和present一个对话框给用户,

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标志,并调用点击链接

。这可以追溯到到Click事件处理程序,该检查

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.

任何想法??

推荐答案

。点击()只有触发事件处理程序的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的链接上的click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆