简体   繁体   中英

Event doesn't fire

I have these bits of code that are supposed to bug two functions and fire events for them. For some reason, however, the event does not seem to trigger. They log to the console as expected, but the event never gets fired.

//Show backstage event
(function( $, oldRem ){
    backstage.show = function(){
        console.log("yup, I'm the right one");
        var resp = oldRem.apply( this, arguments );
        $("#backstageArea").trigger("showBackstage");
        return(resp);
    };
})( jQuery, backstage.show );
//Hide backstage event
(function( $, oldRem ){
    backstage.hide = function(){
        console.log("And so am I.");
        var resp = oldRem.apply( this, arguments );
        if(anim && config.chkAnimate) {setTimeout( 'jQuery("#backstageArea").trigger("hideBackstage")', config.animDuration);}
        else {$("#backstageArea").trigger("hideBackstage");}
        return(resp);
    };
})( jQuery, backstage.hide );

//Resize never logs its console message.
jQuery.bind("hideBackstage", function(){topbar.resize();});
jQuery.bind("showBackstage", function(){topbar.resize();});

You need to specify what element(s) to bind to, so try:

jQuery("#backstageArea").bind(...

instead of

jQuery.bind(...

(And if you're using jQuery version 1.7+ you may like to switch to the .on() method - will have the same effect for this purpose, but is the recommended way of doing things from v1.7 on.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM