callback for .trigger function

前端 未结 4 1062
北海茫月
北海茫月 2021-01-29 03:54

I have the following code:

 $(\"#scheduleLink\").trigger(\"click\");
 alert(\"text\")

This is the click handler:

$(\"#scheduleL         


        
4条回答
  •  旧巷少年郎
    2021-01-29 04:32

    If you don't want move that code replaced by alert alternatively all you can do is fire one event which triggers your behavior replaced by alert.

    $("#scheduleLink").bind("click", (function () {
            loadScheduleEvent();
            $(".wrap_tabs").find("a").removeClass("active"); 
            $(this).addClass("active");
        }));
    
    
    
    $(window).bind("scheduleComplete", (function (event,params) {
          alert(params);
        }));
    

    Now in loadScheduleEvent you have to trigger it.

     function loadScheduleEvent() {
        var eventId = $(".movie").attr("eventId");
        var type = $(".movie").attr("type");
        $("#publicationBlockContent").load("/Publication/EventSchedule?eventId=" + eventId + "&type=" + type,function(){$(window).trigger("scheduleComplete");});
    }
    

    And at last when you what this sequence execute you have to trigger only click event

    $("#scheduleLink").trigger("click");
    

    Also if you dont want scheduleComplete event to be exposed for window you can bind it with your scheduleLink also and get that behavior scoped and specific!!!...

提交回复
热议问题