我想做一个单选按钮,当它被选中时,它将产生一个新的选项卡(带有导航标签的引导面板),在该选项卡中,我可以注册与所选单选按钮相对应的详细信息。例如,当我选择“水果”单选按钮时,它将生成一个新的选项卡,当我转到该选项卡时,我可以输入它的名称、重量等。当我选择“肉”单选按钮时,它将再次生成一个新选项卡。
这是我最喜欢的代码:
<input type="radio" name="id" value="<%= row.id %>" onclick="document.location.href='<%= path_name %>" data-remote="true">
但遗憾的是,数据-remote=“true”不起作用,也不构成新的选项卡。
我找到了一种使用以下代码实现它的方法:
<% @foo.each do |row| %>
<%= link_to(pathname, :remote => "true") do %>
<input type="radio" name="id" value="<%= row.id %>">
<% end %>
<% end %>
但是,使用此代码,无法选择单选按钮(没有表示已选中的标记)。
请任何人帮助我如何使remote=“真”工作或使选择单选按钮看到。
发布于 2017-03-21 01:15:26
jQuery UJS使用表单或链接--而不是单个输入。但是,使用jQuery编写事件处理程序非常简单。
<%= radio_button_tag :id, row.id, data: { href: path_name }, class: 'remote-input' %>
使用data
属性将数据传递给客户端,而不是内联onclick
处理程序。
# place this in
# app/assets/javascripts/
$(document).on("change",".remote-input", function(){
var uri = $(this).data('href');
if (uri){
window.location = uri;
}
// or whatever you want to do.
});
https://stackoverflow.com/questions/42922292
复制相似问题