通过选择选项启用模态(Bootstrap版本3.3.6)?

时间:2016-01-13 02:53:17

标签: twitter-bootstrap twitter-bootstrap-3 modal-dialog html-select bootstrap-modal

示例:当我选择“volvo”选项时,模态会出现。 模态显示不正确。

<>

1 个答案:

答案 0 :(得分:0)

这可能对您有所帮助

<强> HTML

<label>Recinto</label>
<select class="form-control">
  <option>O meu coliseu</option>
  <option>volvo</option>
  <option>A minha arena</option>
  <option>a garagem da minha vizinha</option>
  <option>Na esquina</option>
</select>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        Show what you want
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

<强>的JavaScript

   $(document).ready(function() {
  $('select').change(function() {
    if ($(this).val() == "volvo") {
      $('#myModal').modal('show');
    }
  });

});

Working Fiddle