触发选择时更改另一个选择选项

时间:2019-12-12 19:33:10

标签: jquery jquery-chosen

我想在触发选择时更改另一个选择。我正在使用JQuery选择。

Example with Pure JQuery here

到目前为止,我已经完成:

<form method="post" id="form">
  <div class="row justify-content-center">
    <div class="col-md-4">
      <div class="form-group">
        <select name="categories" class="chosen-select" id="categories">
          <option value=""></option>
          <option value="câmera">câmera</option>
          <option value="celular">Celular</option>
          <option value="computador">Computador</option>
        </select>
      </div>
    </div>
    <div class="col-md-4">
      <div class="form-group">
        <select name="equipments" class="chosen-select" id="equipments">
          <option value=""></option>
          <option value="GoPro">GoPro</option>
          <option value="Samsung A10">Samsung A10</option>
          <option value="Notebook">Notebook</option>
        </select>
      </div>
    </div>
  </div>
</form>

JS:

$(document).ready(function () {
    var categories = $("select[name=categories]")
    var equipments = $("select[name=equipments]")

    categories.chosen()
    $(document).on("click", ".active-result", function () {
        $("#equipments_chosen .result-selected").attr("data-name", $(this).text())
    })

})

我该怎么做?

0 个答案:

没有答案