我有下拉列表,其中包含以下选项
---select an option---
option 1
option 2
option 3
option 4
我想在下拉列表中禁用我的第一个值---选择一个选项---。所以它不能被选为一个选项。
我的代码在这里
<%= f.select :options, options_for_select([[" ---Select an option---", ""], "option 1", "option 2", "option 3", "option 4"]), :style => "margin:20px; width:356px;" %>
最佳答案
在 Ruby 中,它看起来像这样:
<%= f.select options_for_select(["", "Please select", "option 1", "option 2", "option 3", "option 4"], :disabled => "Please select", :selected => "Please select") %>
将一个类分配给 select 标签并将样式移动到您的样式文件会很好
关于ruby-on-rails - 应禁用下拉选项中的第一个值 - Rails,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18720171/