传递在check_box_tag的onclick函数中可变的rails [英] Passing rails variable in a onclick function of check_box_tag

查看:211
本文介绍了传递在check_box_tag的onclick函数中可变的rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用rails 3.0。
在我看来,我想有一个表格,每一行有一个复选框,以及一个onclick事件函数,具体的参数是rails变量

I'm working with rails 3.0. In my view, I'm trying to have a table with a check box for each row, and an onclick event function with specific parameters wich are rails variable

<table>
    <% @joueurs.each do |joueur| %>
<tr>
<td>
<%= check_box_tag(joueur.id,joueur.id, false, :onclick=>"addPlayerToField(<%= joueur.gch %>,<%= joueur.drt %>);")%>
</td>
...
</tr>
<% end %>
</table>

我尝试了很多方法,我没有做到这一点。我知道 joueurs.gch 变量不为空,存在beacaus我使用它在我的意见中的其他地方。

I try many ways and I did not achieve to do it. I know the joueurs.gch variable is not empty and exist beacaus I use it elsewhere in my view.

想要生成类似的东西:

    <table>
    <tr>
<td>
<input id="2036" name="2036" onclick="addPlayerToField(12, 13);" type="checkbox" value="2036"/>
</td>
    </tr>
       <tr>
<td>
<input id="2037" name="2037" onclick="addPlayerToField(22, 10);" type="checkbox" value="2036"/>
</td>
    </tr>
    </table>


推荐答案

我想你可能想要这样: p>

I think you probably want something like this:

<%= check_box_tag(joueur.id, joueur.id, false, :onclick=>"addPlayerToField(#{joueur.gch}, #{joueur.drt});")%>

这篇关于传递在check_box_tag的onclick函数中可变的rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆