我正在学习 ruby on rails。在我的项目中,我使用 collection_select。我的代码是
<%= collection_select(:sport_name,count,Sport.find( :all, :order => 'id' ), :id, :sport_name, {} ,
{:selected => ps.sport.id,
:include_blank => "Select Sport",
:onchange => "hidvalue("+ps.sport.id.to_s+","+count.to_s+")",
:style => "margin:1px 0 0;width:210px;" }) %>
onchange
有效 -selected
无效
如果我改为
<%= collection_select(:sport_name,count,Sport.find( :all, :order => 'id' ),:id, :sport_name,
{:selected => ps.sport.id,
:include_blank => "Select Sport",
:onchange => "hidvalue("+ps.sport.id.to_s+","+count.to_s+")" },
{:style => "margin:1px 0 0;width:210px;" }) %>
onchange
不工作,但selected
工作。我想onchange
和selected
一起使用。这段代码有什么问题?