我想在点击此框时打开侧边栏,但是当我点击按钮时我不想打开侧边栏,这是我的示例代码。
<div class="kanban-level-card js-details">
<p>Antivirus</p>
<div class="btn-group">
<div class="dropdown-menu">
<button>Delete</button>
<button>close opportunity</button>
</div>
</div>
</div>
$(document).on("click", ".js-details", function(e) {
if (!$(e.target).is(".btn-group")) {
$(".sidebar").addClass("visible");
}
});
答案 0 :(得分:0)
只需替换
if (!$(e.target).is(".btn-group")) {
与
if (e.target === this) {
$(document).on("click", ".js-details", function(e) {
if (e.target === this) {
$(".sidebar").addClass("visible");
}
});
$(".js-close").click(function() {
$(".sidebar").removeClass("visible");
});
&#13;
.kanban-level-card {
padding: 10px;
margin-top: 10px;
background-color: #eee;
border: 3px solid green;
color: green;
width: 300px;
cursor: pointer;
}
/* sidebar */
.sidebar {
width: 400px;
height: 100vh;
background-color: #eee;
box-shadow: -1px -2px 38px -3px rgba(133, 131, 133, 1);
position: fixed;
top: 0;
right: -453px;
z-index: 1000;
}
.sidebar.visible {
right: 0px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- card -->
<div class="kanban-level-card js-details">
<p>Antivirus</p>
<div class="btn-group">
<div class="dropdown-menu">
<button>Delete</button>
<button>close opportunity</button>
</div>
</div>
</div>
<!-- sidebar -->
<div class="sidebar js-sidebar">
<button class="js-close">close</button>
</div>
&#13;