gpt4 book ai didi

javascript - Bootstrap JS 无法在 Chrome 中运行

转载 作者:行者123 更新时间:2023-11-28 05:05:13 29 4
gpt4 key购买 nike

此代码适用于 FireFox 和 IE,但不适用于 Chrome。任何想法为什么?感谢帮助。我使用的 Chrome 版本是版本 53.0.2785.143 m。出于某种原因,Chrome 不喜欢被拉入的 JS。我不确定挂断在哪里。

  <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div style="width:100px;">
<select>
<option>Select a language</option>
<option data-toggle="modal" data-target="#myModal">English</option>
<option data-toggle="modal" data-target="#myModal2">Spanish</option>
</select>
<!-- Modals -->
<!-- English Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">English content</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>
</div>
<!-- End English Modal -->
<!-- Spanish Modal -->
<div class="modal fade" id="myModal2" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Spanish content</h4>
</div>
<div class="modal-body">
<p>Some text in the modal2222.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- End Spanish Modal -->
</div>
</body>
</html>

最佳答案

data-toggledata-target 属性被 bootstrap.min.js 脚本用来显示/隐藏模式单击具有这些属性的元素。

在这种情况下,似乎在 Chrome 中没有触发必要的点击事件(很可能是因为您为此使用了 option 元素)。

要解决此问题,您可以添加一些 javascript 代码以在 select 的元素值更改时打开模式。这是一个例子:

<script type="text/javascript">
$(function(){
$("select").change(function(){
if(this.value == "English"){
$("#myModal").modal("show");
}else if(this.value == "Spanish"){
$("#myModal2").modal("show");
}
});
});
</script>

这是一个包含所有代码的工作示例。

$(function(){
$("select").change(function(){
if(this.value == "English"){
$("#myModal").modal("show");
}else if(this.value == "Spanish"){
$("#myModal2").modal("show");
}
});
});
  <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div style="width:100px;">
<select>
<option>Select a language</option>
<option data-toggle="modal" data-target="#myModal">English</option>
<option data-toggle="modal" data-target="#myModal2">Spanish</option>
</select>
<!-- Modals -->
<!-- English Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">English content</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>
</div>
<!-- End English Modal -->
<!-- Spanish Modal -->
<div class="modal fade" id="myModal2" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Spanish content</h4>
</div>
<div class="modal-body">
<p>Some text in the modal2222.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- End Spanish Modal -->
</div>
</body>
</html>

关于javascript - Bootstrap JS 无法在 Chrome 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39863758/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com