根据其他页面中的其他选定值,在模式中的选择框中预先选择一个选项 [英] Pre Select an option in the select box in a modal depending on other selected value from another page

查看:78
本文介绍了根据其他页面中的其他选定值,在模式中的选择框中预先选择一个选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个手风琴是这里的代码:

I have an accordion here is the code:

<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>

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

After clicking every individual Apply Button this modal opens:

<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>

现在发生的事情是选择框中的作业列表与代码中的位置相同,但是我希望每当从单击了该模态的作业链接中打开一个模态时,都将预先选择该作业标题在选择"框中,它会出现在列表的第一位,并且默认情况下会被选中.我想使用jQuery和Ruby on Rails的简单表单来实现它.

What happens now is that the list of jobs in the select box comes as it is in the code, but I want that whenever a modal opens from the job link from which the modal was clicked, the job title will be pre selected in the Select box like it will come up at the first of the list and be selected by default. I want to achieve it using jQuery and Simple form for Ruby on Rails.

推荐答案

您可以为标签添加类和数据选择,然后使用javascript进行预选择

You can add class and data-select for a tags, then use javascript to pre 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'))
})

这篇关于根据其他页面中的其他选定值,在模式中的选择框中预先选择一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆