![](/img/trans.png)
[英]How to add a class on an option tag that belongs to a select tag in rails?
[英]How to add class attribute to select tag in rails 3
我想在我的代碼中使用rails 3中的class屬性添加class屬性
<div >
<%= f.label :type %><br />
<%= f.select "type_id", options_from_collection_for_select(@type,
"type_id","name"),:include_blank=>true%>
</div>
我的問題是我想為這個select標簽添加一個特定的類名以進行驗證。 我嘗試添加
:class=>"myclassname"
但它對我不起作用。解壓我的問題
您可以像這樣添加類屬性。 選中
<%= f.select "type_id",
options_from_collection_for_select(@type, "type_id","name"),
{ :include_blank => true },
{ :class => 'myclassname' } %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.