Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

asp.net - re-firing a click event on a link with jQuery

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");
                }
        }); 

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;
}

returns true but the event never happens....

i need to click the link again manually for it to fire.

any ideas??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

.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. “lose”


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...