开发者

Adding a CSS class to the options tag inside a select wrapper w/ Rails

开发者 https://www.devze.com 2022-12-26 18:43 出处:网络
What if I need to add a class to the options tag? <option value=\"testme1\" class=\"selected\">testme1</option>

What if I need to add a class to the options tag?

<option value="testme1" class="selected">testme1</option>

I haven't been able to do this.

This is what I have

<%=  select(:user, :goalstext, Bodytarget.all.collect {|b| [ b.name, b.id ] },{"class"开发者_如何学JAVA, "test"}, :class => "selected", :class => "selected") %>


Try this:

<%= select(:user, :goalstext, Bodytarget.all.collect {|b| [ b.name, b.id ] },
   {}, {:class => "selected"}) %>

Remember the params' order:

select(object, method, choices, options = {}, html_options = {})

EDIT

I'm sorry, I read your question too fast. My code will add class to the select, not the options. I'll check how to do what you want... sorry!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号