您好,我正在尝试通过 a 打开一个模态,select
并且我有以下代码html
<select id = "numbers" onchange = "myFunction()">
<option value = "1">1</option>
<option value = "2">2</option>
<option value = "3">Click me !</option>
</select>
<div class="container">
<h2>Basic Modal Example</h2>
<!-- Trigger the modal with a button -->
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×
</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-
dismiss="modal">Close</button>
</div>
</div>
</div>
javascript
我正在使用的功能如下:
function myFunction() {
var option_value = document.getElementById("numbers").value;
if (option_value == "3") {
alert("Hai !");
}
}
The problem is that when choosing option 3 it shows me a alert
, what I am looking for is to show a modal made with boostrap, I tried to put a instead of alert
a $('#myModal').modal('show');
but when choosing nothing came out, how else could I do it?
谢谢。
我添加了您只需修改模态内容的解决方案
它通过使用show方法调用模态来工作...检查你的模态是否在同一个文档中,或者是否有外部调用,将jquery集成到你的项目中也很方便。这有效