Javascript 在使用Rails按钮到函数时向js函数传递一个值
我有一个我称之为资源的表,当用户单击一行中的按钮时,我想在jquery对话框中显示一条特定的记录 在我正在做的表格中:Javascript 在使用Rails按钮到函数时向js函数传递一个值,javascript,jquery,ruby-on-rails,Javascript,Jquery,Ruby On Rails,我有一个我称之为资源的表,当用户单击一行中的按钮时,我想在jquery对话框中显示一条特定的记录 在我正在做的表格中: <td><%=button_to_function 'Show','showresource1()',:class =>"ui-button ui-state-default ui-corner-all", :id => resource.id %></td> “ui按钮ui状态默认ui角点全部”,:id=>resource.i
<td><%=button_to_function 'Show','showresource1()',:class =>"ui-button ui-state-default ui-corner-all", :id => resource.id %></td>
“ui按钮ui状态默认ui角点全部”,:id=>resource.id%>
然后在javascript中,我想将resource.id传递给jQuery对话框并打开该对话框:
<script type="text/javascript" charset="utf-8">
function showresource1()
{
jQuery("#resource_details").load( 'http://localhost:3000/resources/show/4').dialog('open');
}
</script>
函数showresource1()
{
jQuery(“#资源_详细信息”).load('http://localhost:3000/resources/show/4)。对话框(“打开”);
}
我可以打开对话框并加载这个静态URL,但是我无法将resource.id从button_to_函数重新传递到js函数
按钮功能正确吗?如果正确,我如何在js中定义URL?应该与下面的代码类似
<% for res_id in ids %>
<%=button_to_function "Show", "show_resource('#{res_id}')" %>
<% end %>
<script type="text/javascript" charset="utf-8">
function show_resource(res_id)
{
jQuery("#resource_details").load( 'http://localhost:3000/resources/show/' + res_id).dialog('open');
}
</script>
功能显示资源(资源id)
{
jQuery(“#资源_详细信息”).load('http://localhost:3000/resources/show/“+res_id).对话框('open');
}