如何将下拉菜单更改为单选按钮? [英] How do I change a dropdown menu to radio buttons?
本文介绍了如何将下拉菜单更改为单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有选择列表的下拉菜单:
I have a drop-down menu with a list of choices:
select_tag(:"answers[#{question.question_no}]", options_for_select( [['Agree Strongly', 7], ['Agree Mostly', 6], ['Agree Somewhat', 5], ['Neither Agree Nor Disagree', 4], ['Disagree Somewhat', 3], ['Disagree Mostly', 2], ['Disagree Strongly', 1]] ))
我希望它显示七个单选按钮.这怎么可能.如果有的话?
I would like it so that it displays seven radio buttons instead. How is this possible. if at all?
推荐答案
<%- [['Agree Strongly', 7],
['Agree Mostly', 6],
['Agree Somewhat', 5],
['Neither Agree Nor Disagree', 4],
['Disagree Somewhat', 3],
['Disagree Mostly', 2],
['Disagree Strongly', 1]].each do |button| %>
<%= radio_button_tag :name, button.first, :value => button.last %>
<% end %>
甚至更好地列出控制器
...控制器
def some_action
@choices = [['Agree Strongly', 7],
['Agree Mostly', 6],
['Agree Somewhat', 5],
['Neither Agree Nor Disagree', 4],
['Disagree Somewhat', 3],
['Disagree Mostly', 2],
['Disagree Strongly', 1]]
end
...观看次数
<% @choices.each do |button| %>
<%= radio_button_tag :name, button.first, :value => button.last %>
<% end %>
这篇关于如何将下拉菜单更改为单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文