我有一个html css代码的通知下拉框,问题是我不能点击标签,同时我尝试与javaScript也不能工作,我不能理解这个问题,请告诉我如何使一个可点击的标签。
$('.toparea-right > .setting-area > li').on("click",function(){
$(this).siblings().children('div').removeClass('active');
$(this).children('div').addClass('active');
return false;
});
//------- remove class active on body
$("body *").not('.toparea-right > .setting-area > li').on("click", function() {
$(".toparea-right > .setting-area > li > div").removeClass('active');
return true;
});.dropdowns {
background: #FFF none repeat scroll 0 0;
border: 1px solid #e1e8ed;
list-style: outside none none;
max-height: 294px;
overflow: auto;
padding-left: 0;
position: absolute;
right: -175px;
text-align: left;
top: 55px;
width: 440px;
opacity: 0;
visibility: hidden;
-webkit-transition: all 0.3s linear 0s;
-moz-transition: all 0.3s linear 0s;
transition: all 0.3s linear 0s;
}
.dropdowns.active{
opacity: 1;
visibility: visible;
}
.drops-menu {
list-style: outside none none;
padding-left: 0;
}
.drops-menu > li > a {
border-bottom: 1px solid #e1e8ed;
display: inline-block;
padding: 5px;
width: 100%;
}
.dropdowns > h6{
font-size: 15px;
}
.drops-menu > li > .tag {
color: #fff;
display: inline-block;
font-size: 11px;
padding: 0 6px;
position: absolute;
right: 0;
top: 0;
}
.drops-menu > li:nth-child(2n) > a {
background: whitesmoke none repeat scroll 0 0;
}
.drops-menu > li a img {
display: inline-block;
vertical-align: middle;
width: 10%;
border-radius: 100%;
margin-bottom: 10px;
margin-left: 10px;
height: 45px;
}
.mesg-meta {
display: inline-block;
padding-left: 30px;
vertical-align: middle;
width: -1%;
color: #000000;
padding-top: -21px;
top: 18px;
margin-top: 0px;
line-height: 25px;
}
.mesg-meta > h6 {
font-size: 13.5px;
font-weight: 600;
letter-spacing: 0.3px;
margin-bottom: 0;
text-transform: capitalize;
margin-left: -15px;
}
.mesg-meta > span {
color: #000000;
display: inline-block;
font-size: 12px;
line-height: 15px;
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
}
.mesg-meta > i {
color: #000000;
font-size: 12px;
font-style: normal;
margin-left: -15px;
}
.drops-menu > li > a:hover {
background: #fafafa none repeat scroll 0 0;
}
.dropdowns > span {
border-bottom: 1px solid #ccc;
display: inline-block;
font-size: 14px;
padding: 0px 10px;
text-align: center;
width: 100%;
height: 59px;
margin-top: 0px;
}
.dropdowns > a.more-mesg {
display: inline-block;
font-size: 14px;
padding-bottom: 5px;
text-align: center;
text-transform: capitalize;
width: 100%;
}
.blue{background: #337ab7;}
.red{background: #ff0000;}
.green{background: #33b7a0;}
.dropdowns.active > a {
background: #fafafa none repeat scroll 0 0;
display: block;
font-size: 13px;
margin-bottom: 2px;
padding: 0px 0px;
text-align: center;
}
.dropdowns.active > a i {
font-size: 11px;
left: 8px;
position: absolute;
top: 10px;
}
.dropdowns.languages {
width: 100px;
}
.dropdowns.active > a:hover {
background: #f1f1f1 none repeat scroll 0 0;
}<div class="toparea-right">
<ul class="setting-area">
<li>
<a href="#"><i class="far fa-newspaper"></i></a>
<span class="notifi-count" id="displayNotiCount">00</span>
<a href="#" class="a-left">Notifications</a>
<div class="dropdowns">
<ul class="drops-menu">
<li>
<a href="view-post.php" onclick="window.location.href('view-post.php')" title="">
<div class="mesg-meta-notification">
<h6>Bruce Wayne</h6>
<span>is commented in your post!</span>
<i>0 min ago</i>
</div>
</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
我附加了我的CSS和HTML代码,我尝试它的工作,但URL是在另一个选项卡中打开。我需要打开同一选项卡中的网址,请告诉我如何解决这个问题的解决方案。
发布于 2019-01-26 17:44:40
在您的代码中,dropdown是不可见的。
我认为,当你点击“通知”时,你必须通过切换(添加和删除) <a href="#" class="a-left"> Notifications </a>标签上的“活动”类来切换(隐藏/显示)下拉菜单。
一旦您的下拉列表可见。点击应该如你所愿的那样工作。
示例工作代码:
<a href="#" class="a-left" onClick="toggleDropdownVisibility()">Notifications</a>
<script>
function toggleDropdownVisibility(event) {
var notificationBell = event.target;
if (notificationBell.classList.contains('active')) {
notificationBell.classList.remove('active');
} else {
notificationBell.classList.add('active');
}
}
</script>除此之外,请删除onclick="window.location.href('view-post.php')",因为window.location.href不是一个函数,而是一个可以分配url的属性。比如window.location.href='view-post.php'。但是你可以完全删除这个onclick,因为它是不需要的。
发布于 2019-01-26 18:59:01
您的代码在这里看起来很好,只是我不明白为什么.dropdown css类上有opacity:0和visibility:hidden。这使得您的控件无法访问。但一旦我在css中删除了这两个属性,我就能正常工作(在最新版本的Chrome上)
我的建议是:
对于标签,你可以使用这个:https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/。不需要太多的自定义JS。
发布于 2019-01-28 12:44:54
我有解决这个问题的办法,我试过了,它起作用了。
<div class="toparea-right">
<ul class="setting-area">
<li>
<a href="#"><i class="far fa-newspaper"></i></a>
<span class="notifi-count" id="displayNotiCount">00</span>
<a href="#" class="a-left">Notifications</a>
<div class="dropdowns" id="MmailNoti">
<ul class="drops-menu">
<li>
<a href="view-post.php" onclick="window.location.href('view-post.php')" title="">
<div class="mesg-meta-notification">
<h6>Bruce Wayne</h6>
<span>is commented in your post!</span>
<i>0 min ago</i>
</div>
</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
<script>
// When the user clicks on div, open the popup
function myFunction() {
var popup = document.getElementById("MmailNoti");
popup.classList.toggle("show");
}
</script>https://stackoverflow.com/questions/54377009
复制相似问题