[英]display bootstrap modal popup from javascript not working
I am trying to open a modal popup from a javascript block. 我正在尝试从JavaScript块打开模式弹出窗口。 This is a basic modal that I found in w3schools: http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_modal&stacked=h
这是我在w3schools中发现的一种基本模式: http : //www.w3schools.com/bootstrap/tryit.asp? filename = trybs_ref_js_modal&stacked = h
Here is my code : 这是我的代码:
<script>
function showModal(){
window.location.href = '#myModal';
}
</script>
<!-- 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>
Instead of JavaScript you an use default bootstrap function
您可以使用默认的
bootstrap function
代替JavaScript。
function showModal(){
$('#myModal').modal('show')
}
window.location.href
does not have what is known as a setter, which means it cannot be assigned a new value. window.location.href
没有所谓的setter,这意味着无法为它分配新值。 It does have a getter as standard (a requirement, really), so you can get it. 它确实有一个标准的吸气剂(确实是一个要求),所以您可以得到它。
If you want to open a link, try window.open("#myModal");
如果要打开链接,请尝试
window.open("#myModal");
, or use jQuery with $('#myModal').modal('show');
,或将jQuery与
$('#myModal').modal('show');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.