我正在学习 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一起使用。这段代码有什么问题?