【问题标题】:Event bindings lost after refreshing div刷新 div 后事件绑定丢失
【发布时间】:2015-07-15 20:40:56
【问题描述】:

我正在使用 rails gem best_in_place 并尝试在提交时重新加载它所在的 div。

$('.best_in_place').bind("ajax:success", function(){
    $(.'div').load(location.href+" .div>*","");
});

但是,一旦我刷新 div,事件绑定就消失了。我该如何解决这个问题?

【问题讨论】:

    标签: javascript jquery ruby-on-rails ajax best-in-place


    【解决方案1】:

    如果您再次重新创建 div,则绑定不起作用。在这种情况下,最好使用 'on' 而不是 live 的 bind。

    $('.best_in_place').on("ajax:success", function(){
        $(.'div').load(location.href+" .div>*","");
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-26
      • 2017-10-21
      • 2014-03-23
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      相关资源
      最近更新 更多