Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rails 4-简单表单-Jquery-如何向选择框中的选项添加类_Jquery_Ruby On Rails - Fatal编程技术网

Rails 4-简单表单-Jquery-如何向选择框中的选项添加类

Rails 4-简单表单-Jquery-如何向选择框中的选项添加类,jquery,ruby-on-rails,Jquery,Ruby On Rails,我很困惑,非常感谢你的帮助。请告诉我如何将类添加到选择框中的特定选项 如图所示,我只想在选项中添加一个类:X男X女,但我不确定如何添加 _form.html.erb <%= simple_form_for [@user, @social] do |f| %> <%= f.error_notification %> <div class="form-inputs"> <%= f.association :category_quantity

我很困惑,非常感谢你的帮助。请告诉我如何将类添加到选择框中的特定选项

如图所示,我只想在选项中添加一个类:
X男X女
,但我不确定如何添加

_form.html.erb

<%= simple_form_for [@user, @social] do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.association :category_quantitygender, collection: CategoryQuantitygender.all, prompt: "select a category", label: "Quantity Gender Selection", input_html: { class: 'category_select' } %>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>

请按照选择框中添加类的链接进行操作

试试这个

$('#social_category_quantitygender_id').find("option[value='4']").addClass("here")

希望这对你有用………

谢谢@akshay!你的答案是最好的,因为它允许我将一个类放在一个特定的选项值上。非常感谢你@阿特洛:谢谢你:)
$('#social_category_quantitygender_id').find("option[value='4']").addClass("here")