Rails按钮id和单击按钮事件

时间:2013-09-25 17:14:49

标签: javascript jquery ruby-on-rails

我正在使用rails app,这是我正在使用的代码:

<%= button_to "New", :action => "update", remote: true%>

现在我想要按钮ID,以便我可以在点击时启动JavaScript事件,最初使用的简单html按钮是:

<input id="btn" type="button" value="Save" action="update" alignment="center" />

任何猜测?

1 个答案:

答案 0 :(得分:0)

正如documentation所示,没有办法直接这样做。我发现的最好的方法是向父类添加一个id - span效果很好。

<span id="btn">
  <%= button_to "New", :action => "update", remote: true%>
</span>