我正在使用rails app,这是我正在使用的代码:
<%= button_to "New", :action => "update", remote: true%>
现在我想要按钮ID,以便我可以在点击时启动JavaScript事件,最初使用的简单html按钮是:
<input id="btn" type="button" value="Save" action="update" alignment="center" />
任何猜测?
答案 0 :(得分:0)
正如documentation所示,没有办法直接这样做。我发现的最好的方法是向父类添加一个id - span
效果很好。
<span id="btn">
<%= button_to "New", :action => "update", remote: true%>
</span>