Javascript 即使我删除了其他bootstrap.min.js,模态框仍会消失
我一直在努力使我的模态盒停止消失,但我所做的一切都不起作用。我甚至使用了我在网上看到的一些线程的解决方案,但它们不起作用。我怎样才能不让它消失 这是我的代码:Javascript 即使我删除了其他bootstrap.min.js,模态框仍会消失,javascript,html,css,twitter-bootstrap,Javascript,Html,Css,Twitter Bootstrap,我一直在努力使我的模态盒停止消失,但我所做的一切都不起作用。我甚至使用了我在网上看到的一些线程的解决方案,但它们不起作用。我怎样才能不让它消失 这是我的代码: <html> <head> <title> Test Slides </title> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet"
<html>
<head>
<title> Test Slides </title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<style type="text/css">
.carousel-control {
padding-top:10%;
width:5%;
}
/* Video icon overlay on image */
.videos img {
width:100%;
height:auto;
}
a.video {
float: left;
position: relative;
}
a.video span {
width: 100%;
height: 100%;
position: absolute;
background: url("images/lightbox-play.png") no-repeat;
background-position: 50% 50%;
background-size: 15%;
}
@media screen and (max-width: 480px) {
a.video span {
background-size: 400%;
}
}
/* gutter spaces */
.row.no-gutter [class*='col-']:not(:first-child),
.row.no-gutter [class*='col-']:not(:last-child) {
padding-right:0;
padding-left:0;
}
.row.no-gutter {
margin-left: 0;
margin-right: 0;
}
/* Style the Image Used to Trigger the Modal */
#myImg {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
#myImg:hover {opacity: 0.7;}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}
/* Modal Content (Image) */
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}
/* Modal Video*/
.modal iframe {
position: absolute;
left: 20%;
top: 10%;
}
/* Add Animation - Zoom in the Modal */
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}
@-webkit-keyframes zoom {
from {-webkit-transform:scale(0)}
to {-webkit-transform:scale(1)}
}
@keyframes zoom {
from {transform:scale(0)}
to {transform:scale(1)}
}
/* The Close Button */
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}
/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
.modal-content {
width: 100%;
}
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="col-md-12">
<h1>Nerdic Consult</h1>
<div id="myCarousel" class="carousel slide">
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active">
<div class="row no-gutter">
<div id="myImg1" class="col-sm-3 videos"><a href="" class="video"><span></span><img src="images/image 1.jpg" alt="Image" class="img-responsive"></a>
</div>
<div class="col-sm-3 videos"><a href="" class="video"><span></span><img src="images/image 2.jpg" alt="Image" class="img-responsive"></a>
</div>
<div class="col-sm-3 videos"><a href="" class="video"><span></span><img src="images/image 3.jpg" alt="Image" class="img-responsive"></a>
</div>
<div class="col-sm-3 videos"><a href="" class="video"><span></span><img src="images/image 4.jpg" alt="Image" class="img-responsive"></a>
</div>
</div>
<!--/row-->
</div>
<!--/item-->
<div class="item">
<div class="row no-gutter">
<div class="col-sm-3 videos"><a href="" class="video"><span></span><img src="images/image 5.jpg" alt="Image" class="img-responsive"></a>
</div>
<div class="col-sm-3 videos"><a href="" class="video"><span></span><img src="images/image 6.jpg" alt="Image" class="img-responsive"></a>
</div>
<div class="col-sm-3 videos"><a href="" class="video"><span></span><img src="images/image 7.jpg" alt="Image" class="img-responsive"></a>
</div>
<div class="col-sm-3 videos"><a href="" class="video"><span></span><img src="images/image 8.jpg" alt="Image" class="img-responsive"></a>
</div>
</div>
<!--/row-->
</div>
<!--/item-->
</div>
<!--/carousel-inner--> <a class="left carousel-control" href="#myCarousel" data-slide="prev"><img src="images/lightbox-prev.png"/></a>
<a class="right carousel-control" href="#myCarousel" data-slide="next"><img src="images/lightbox-next.png"/></a>
</div>
<!--/myCarousel-->
<!-- The Modal -->
<div id="myModal1" class="modal">
<!-- The Close Button -->
<span class="close" onclick="document.getElementById('myModal1').style.display='none'">×</span>
<!-- Modal Content (The Video) -->
<iframe width="60%" height="60%" src="https://www.youtube.com/embed/AhTbZTLkIIs" frameborder="0" allowfullscreen=""></iframe>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#myCarousel').carousel({
interval: 10000
})
$('#myCarousel').on('slid.bs.carousel', function() {
//alert("slid");
});
});
// Get the modal
var modal = document.getElementById('myModal1');
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg1');
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
</script>
</body>
</html>
试纸
.传送带控制{
垫面:10%;
宽度:5%;
}
/*视频图标覆盖在图像上*/
.视频img{
宽度:100%;
高度:自动;
}
a、 录像带{
浮动:左;
位置:相对位置;
}
a、 视频跨度{
宽度:100%;
身高:100%;
位置:绝对位置;
背景:url(“images/lightbox play.png”)不重复;
背景位置:50%50%;
背景大小:15%;
}
@媒体屏幕和屏幕(最大宽度:480px){
a、 视频跨度{
背景大小:400%;
}
}
/*排水沟空间*/
.row.no-gotter[class*='col-']:非(:第一个子级),
.row.no-gotter[class*='col-']:非(:最后一个子级){
右边填充:0;
左侧填充:0;
}
.第二排{
左边距:0;
右边距:0;
}
/*设置用于触发模式的图像的样式*/
#myImg{
边界半径:5px;
光标:指针;
过渡:0.3s;
}
#myImg:hover{opacity:0.7;}
/*模态(背景)*/
.莫代尔{
显示:无;/*默认情况下隐藏*/
位置:固定;/*保持原位*/
z指数:1;/*位于顶部*/
填充顶部:100px;/*框的位置*/
左:0;
排名:0;
宽度:100%;/*全宽*/
高度:100%;/*全高*/
溢出:自动;/*根据需要启用滚动*/
背景色:rgb(0,0,0);/*回退色*/
背景色:rgba(0,0,0,0.9);/*黑色w/不透明度*/
}
/*模态内容(图像)*/
.模态内容{
保证金:自动;
显示:块;
宽度:80%;
最大宽度:700px;
}
/*模态视频*/
.模态iframe{
位置:绝对位置;
左:20%;
排名前10%;
}
/*添加动画-在模式中缩放*/
.模式内容#标题{
-webkit动画名称:缩放;
-webkit动画持续时间:0.6s;
动画名称:缩放;
动画持续时间:0.6s;
}
@-webkit关键帧缩放{
来自{-webkit变换:缩放(0)}
到{-webkit转换:缩放(1)}
}
@关键帧缩放{
来自{transform:scale(0)}
到{变换:比例(1)}
}
/*关闭按钮*/
.结束{
位置:绝对位置;
顶部:15px;
右:35px;
颜色:#f1f1;
字体大小:40px;
字体大小:粗体;
过渡:0.3s;
}
.关闭:悬停,
.结束:聚焦{
颜色:#bbb;
文字装饰:无;
光标:指针;
}
/*较小屏幕上的100%图像宽度*/
@仅介质屏幕和(最大宽度:700px){
.模态内容{
宽度:100%;
}
}
书呆子咨询
&时代;
$(文档).ready(函数(){
$('myCarousel')。carousel({
间隔:10000
})
$('#myCarousel').on('slided.bs.carousel',function(){
//警惕(“滑动”);
});
});
//获取模态
var modal=document.getElementById('myModal1');
//获取图像并将其插入模式-使用其“alt”文本作为标题
var img=document.getElementById('myImg1');
img.onclick=函数(){
modal.style.display=“块”;
modalImg.src=this.src;
captionText.innerHTML=this.alt;
}
//获取关闭模态的元素
var span=document.getElementsByClassName(“关闭”)[0];
//当用户单击(x)时,关闭模式对话框
span.onclick=函数(){
modal.style.display=“无”;
}
非常感谢,不用麻烦了。我发现是锚定标记中的href
造成的。我删除了锚定标记中的href=“”
,模式框保留下来。你想实现什么?既然你已经加载了jQuery(因为它是引导的依赖项),为什么要使用getElementById等?欢迎访问该网站-感谢你回答你的问题。