我的网页中有一个使用Bootstrap的模态。我在其中添加了锚标签,其中有href链接。当我尝试单击该锚元素时,它不可单击。锚标签在Modal中不起作用。
请帮我解决这个问题。
请在下面找到代码 -
<div class="portfolio-modal modal fade" id="editionsModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-content">
<div class="close-modal" data-dismiss="modal">
<div class="lr">
<div class="rl">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="col-sm-3">
<a href="hingoli.html" data-target="#" style="text-decoration: none;">
<div style="padding:15px; color:#181818; text-align: center; ">
<h4>Hingoli</h4>
</div>
<img src="pages/hingoli/1.jpg" style="margin: 0 auto; display: block;" class="modal-img" alt="">
</a>
</div>
<div class="col-sm-3">
<a href="parbhani.html" class="portfolio-link" style="text-decoration: none;">
<div style="padding:15px; color:#181818; text-align: center; ">
<h4>Parbhani</h4>
</div>
<img src="pages/parbhani/1.jpg" style="margin: 0 auto; display: block;" class="modal-img" alt="">
</a>
</div>
<div class="modal-body">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
检查一下,我使用了clearfix div。但如果我不想clearfix,那我就用了
(div class="modal-body col-sm-3"
)因为链接div具有浮点值
但modal-body
没有。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#editionsModal">Open Modal</button>
<div class="portfolio-modal modal fade" id="editionsModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-content">
<div class="close-modal" data-dismiss="modal">
<div class="lr">
<div class="rl">
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="col-sm-3">
<a href="hingoli.html" data-target="#" style="text-decoration: none;">
<div style="padding:15px; color:#181818; text-align: center; ">
<h4>Hingoli</h4>
</div>
<img src="pages/hingoli/1.jpg" style="margin: 0 auto; display: block;" class="modal-img" alt="">
</a>
</div>
<div class="col-sm-3">
<a href="parbhani.html" class="portfolio-link" style="text-decoration: none;">
<div style="padding:15px; color:#181818; text-align: center; ">
<h4>Parbhani</h4>
</div>
<img src="pages/parbhani/1.jpg" style="margin: 0 auto; display: block;" class="modal-img" alt="">
</a>
</div>
<div class="clearfix"></div>
<div class="modal-body">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
答案 1 :(得分:0)
我在Bootstrap 4中有相同的行为,结果发现.modal-dialog
div具有pointer-events: none;
属性,该属性会禁用链接。设置为pointer-events: all;
对我来说是固定的。
答案 2 :(得分:0)
请尝试此代码!
$('#editionsModal .container a').on('click',function( ev){
var $button=$(ev.target);
ev.preventDefault();
$(this).closest('.modal').on('hidden.bs.modal',function(e){
var $href=$button.attr('href');
window.location.href=$href;
});
});