根据另一页的其他 selected 值,在模态的 select 框中预先 Select 一个选项

Pre Select an option in the select box in a modal depending on other selected value from another page

我手风琴这里是代码:

<div class="accordion">
            <div class="accordion-title accordion-area">
              <a href="#joinus/jr-software-engineer/" id="accordion-link">Junior Software Engineer</a>
            </div>
            <div class="accordion-container">This is the Body <a href="#apply" class="btn btn-hire"> Apply Now</a></div>
            <div class="accordion-title accordion-area">
              <a href="#joinus/sr-software-engineer/" id="accordion-link">Senior Software Engineer</a>
            </div>
            <div class="accordion-container">This is the Body <a href="#apply" class="btn btn-hire"> Apply Now</a></div>
            <div class="accordion-title accordion-area">
              <a href="#joinus/software-engineer-intern/" id="accordion-link">Intern Software Engineer</a>
            </div>
            <div class="accordion-container">This is the Body <a href="#apply" class="btn btn-hire"> Apply Now</a></div>
</div>

单击每个单独的“应用”按钮后,此模式打开:

<div id="apply" class="modal-holder">
  <a class="base-close" href="#joinus"></a>
  <div class="modal">
    <a class="close-modal" href="#joinus"><i class="fa fa-times"></i></a>
    <div class="modal-header">
      Apply
    </div>
    <div class="modal-body">
      <%= form_for @job_application do |f| %>
        <div class="row" role="list">
          <div class="col-6">
            <div class="form-holder">
              <%= label_tag(:role, 'Job Position *') %>
              <%= f.select :role, options_for_select(['Junior Software Engineer','Senior Software Engineer', 'Intern Software Engineer']), class: 'text-box' %>
            </div>
          </div>  
        </div>
        <%= submit_tag 'Send', class: 'btn btn-primary btn-large' %>
      <% end %>
    </div>
  </div>
</div>

现在发生的是 select 框中的作业列表与代码中的一样,但我希望每当模态从作业 link 打开模态时单击后,职位名称将预先 select 编辑在 Select 框中,就像它会出现在列表的第一个一样,默认情况下是 select 编辑的。我想在 Rails 上使用 jQuery 和 Ruby 的简单形式来实现它。

你可以为标签添加class和数据-select,然后使用javascript预先select

<a href="#apply" class="btn btn-hire class-of-a-tag" data-select="Junior Software Engineer"> Apply Now</a></div>

尝试

$('.class-of-a-tag').click(function() {
  $('#id-of-select-box').val($(this).data('select'))
})