javascript - 如何修复可点击的 href 标签?

标签 javascript php jquery html css

我有一个用于通知下拉框的 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 在另一个选项卡中打开。我需要在同一个选项卡中打开 url 请告诉我如何解决这个问题。

最佳答案

在您的代码中,下拉列表从未显示过。

我认为,您在单击“通知”时必须通过切换(添加和删除)<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,因为它不需要。

关于javascript - 如何修复可点击的 href 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54377009/

相关文章:

php - 如何返回具有最高值的数组元素?

javascript - 鼠标光标在 Jquery 中的按键事件中消失

javascript - jQuery 中的 HTML 字符串返回错误

Angular 2 中的 JavaScript 堆内存不足

javascript - 如何将整数数组转换为人力车的 x/y 坐标

javascript - Durandal Weyland 优化无法处理 require 函数

javascript - 使用 jquery 显示 div 内容

javascript - appendChild无法使用音频控件

php - Eloquent 嵌套 whereHas

php - 如何计算处理图像所需的内存?