【问题标题】:Rails 4 + Jquery redirect pages using jquery then back, the jquery is not workingRails 4 + Jquery 使用 jquery 重定向页面然后返回,jquery 不工作
【发布时间】:2015-03-31 15:35:04
【问题描述】:

我在使用 jquery 的 ruby​​ 上遇到此代码问题,我正在使用 Jquery 进行重定向,然后使用后退按钮返回。而且它只在第一次工作,如果你从重定向返回它只是不绑定到 DOM。

代码:

$(function(){
    $('tr.item').bind("click", function(){
            window.location.href = "/products/" + $(this).attr('id');
        // Or, we can grab the HREF from the first anchor:
        // window.location = $('a:first', this).attr('href');
    });
});

PS:我已经尝试过 window.onunload 技巧。

【问题讨论】:

    标签: jquery ruby ruby-on-rails-4


    【解决方案1】:

    这是我的解决方案,基于:JQuery click function not working after removing and adding back elements

    $(function(){
        $(document).on("click", 'tr.item', function(){
                window.location.href = "/products/" + $(this).attr('id');
            // Or, we can grab the HREF from the first anchor:
            // window.location = $('a:first', this).attr('href');
        });
    });
    

    我不明白为什么在从链接执行返回后这会起作用,但似乎文档需要是根对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-19
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      • 2013-06-14
      相关资源
      最近更新 更多