jQuery的;创建类似于rails的链接

时间:2016-02-23 19:23:57

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

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

Rails链接;

<%= 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>

链接不起作用;

1 个答案:

答案 0 :(得分:0)

使用JQuery

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