Ruby on Rails 下拉列表<选择>菜单 - 如何为选项设置样式或应用类?选择>
如何在 ruby on Rails 3 中创建颜色下拉菜单?
我知道如何在 html、css 和 javascript 中执行此操作,如下所示,但我不知道如何在 ruby on Rails 3 中执行此操作。
理想情况下,使用 collection_select 或 collection_options_for_select 构建
我想要得到的部分代码是:
<select>
<option value="">Highlight</option>
<option value="#000000" style="background-color: Black;color: #FFFFFF;">Black</option>
<option value="#808080" style="background-color: Gray;">Gray</option>
<option value="#A9A9A9" style="background-color: DarkGray;">DarkGray</option>
How can I create a colors dropdown menu in ruby on rails 3?
I know how to do it in html, css and javascript as following but i dont know how in ruby on rails 3.
Ideally using collection_select or collection_options_for_select other collection objects that build <select>
's and <options>
's. Using these would be preferred to manually looping through the collection and spitting out pieces and styling each piece though that could be done.
Code partial of what I am trying to get is:
<select>
<option value="">Highlight</option>
<option value="#000000" style="background-color: Black;color: #FFFFFF;">Black</option>
<option value="#808080" style="background-color: Gray;">Gray</option>
<option value="#A9A9A9" style="background-color: DarkGray;">DarkGray</option>
Full Code is at:
http://pietschsoft.com/post/2004/09/20/Color-the-background-of-items-in-a-Dropdown-box-in-your-HTML-pages.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Rails Helper
options_for_select
绝对允许您为各个选项提供样式信息。这直接来自
options_for_select
的文档给出
并
给出
在你的情况下它将是
Rails Helper
options_for_select
absolutely allows you to provide styling information for individual options.This is straight from the documentation of
options_for_select
gives
and
gives
And in your case it would be
据我所知,内置的助手不支持它。
但是,您可以使用以下命令自行推出:
然后按如下方式使用它:
The built in helpers don't support it as far as I know.
However you can roll your own with:
and then use it as follow: