【问题标题】:jquery; create link similar to railsjQuery;创建类似于 rails 的链接
【发布时间】:2016-02-23 19:23:56
【问题描述】:

这可能是一个愚蠢的问题,但我正在尝试复制我在 rails 但在 jquery 中创建的链接。

导轨链接;

<%= link_to 'unfollow', dashboard_follow_index_path(blog: n['blog_name']), method: :post, remote: true, class: 'f-button' %>

输出;

<a class="f-button" data-remote="true" rel="nofollow" data-method="post" href="/dashboard/follow?blog=b">unfollow</a>

到目前为止我在 jquery 中得到了什么;

var newLink = $("<a />", {
          class : "f-button",
          href : "I know how to get this blog name.",
          method : "post",
          rel : "nofollow",
          text : "follow",
        });

输出;

<a rel="nofollow" method="post" href="/dashboard/follow?blog=b" id="f-button">follow</a>

链接不一样;

【问题讨论】:

  • RoR 在幕后做了很多 Javascript。没有它,该链接将永远无法发布。您可以在 jQuery 中复制它,查看jQuery.post()

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


【解决方案1】:

使用 JQuery

var newLink = $("<a />", {
      'class' : 'f-button',
      name : "link",
      href : "you know how to get this blog name.",
      method : "post",
      rel : "nofollow",
      text : "follow"
});

【讨论】:

猜你喜欢
  • 2016-12-11
  • 2012-08-16
  • 1970-01-01
  • 2013-09-01
  • 2012-07-09
  • 1970-01-01
  • 2016-07-16
  • 2019-01-21
  • 1970-01-01
相关资源
最近更新 更多