开发者

To check the default select value tag!

I have a question.Here is the code!

  f.select(:departments,Department.all.collect{|c|[c.name,c.id]},{},:size=>10,:multiple => ture)
   class Emergency
     has many :departments
   end

the html source like this:

<select id="emergency_departments" multiple="multiple" name="emergency[departments][]" s开发者_如何学Cize="10"><option value ="">""</option>....</select>

now I want to get the default selected tag , who can tell me how ?


You want to find the value of the option selected? Is that right?

If so, and you know your way around a bit of JQuery, this is how you do it:

$("#emergency_departments option:selected").val()


Now I know the question , i used the tag "collection_select" to solve this problem.Its method like this, f.collection_select(:departments,Department.all,:id,:name,)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜