下面这个弹出框,想实现如下效果:
1、点击弹出框右上角的叉时,弹出框关闭;
2、点击弹出框本身以外的地方时,弹出框关闭;
3、点击弹出框本身,弹出框不关闭(那个叉除外);
Html:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link href="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet">
<style>
#card1 {
width: 40rem;
position: absolute;
display: none;
right: 0;
left: auto;
top: 100%;
z-index: 1000;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 1rem;
color: #373a3c;
text-align: left;
list-style: none;
background-color: #fff;
-webkit-background-clip: padding-box;
background-clip: padding-box;
border: 1px solid rgba(0, 0, 0, .15);
border-radius: .25rem;
}
</style>
</head>
<body>
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control" aria-label="Text input with dropdown button">
<div class="input-group-btn">
<button id="button1" type="button" class="btn btn-secondary dropdown-toggle"
aria-haspopup="true" aria-expanded="false">
</button>
<div class="card dropdown-menu-right" id="card1">
<div class="card-header">
弹出框
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
</div>
<div class="card-block">
<h4 class="card-title">Special title treatment</h4>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.bootcss.com/jquery/2.2.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/tether/1.1.1/js/tether.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
</body>
</html>
Javascript:
<script>
$('#button1').click(function () {
var menu = $('#card1');
if (menu.is(":hidden")) {
menu.show();
} else {
menu.hide();
}
});
<script type="text/javascript">
$(function(){
$(window).click(function(){
$("#card1").hide();
});
$("#button1").click(function(e){
e.stopPropagation();
$(this).siblings("#card1").show();
});
$("button.close").click(function(){
$(this).parents("#card1").hide();
});
$("#card1,.form-control").click(function(e){
e.stopPropagation();
});
})
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。