【问题标题】:Event doesn't fire事件不触发
【发布时间】:2012-09-26 13:37:29
【问题描述】:

我有这些代码应该会错误地处理两个函数并为它们触发事件。然而,由于某种原因,该事件似乎没有触发。他们按预期登录到控制台,但该事件永远不会被触发。

//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();});

【问题讨论】:

  • 你试过jQuery("#backstageArea").bind(...而不是jQuery.bind(...吗?
  • 做到了。你能把它放在答案中吗?
  • 如果您还没有,可以查看Firebug,这是调试 javascript 和其他错误的绝佳工具。

标签: javascript jquery html tiddlywiki


【解决方案1】:

您需要指定bind 的元素,所以试试:

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

而不是

jQuery.bind(...

(如果您使用的是 jQuery 1.7+ 版本,您可能希望切换到 .on() method - 为此目的会产生相同的效果,但这是从 v1.7 开始推荐的做事方式。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 2015-11-06
    • 2018-08-15
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    相关资源
    最近更新 更多