子页面没有变为活动页面

sub pages is not becoming active

本文关键字:活动页      更新时间:2023-09-26

在这里我有添加,查看和编辑页面。当我点击添加和查看页面时,页面变得活跃,父页面也变得活跃。但是,当我点击编辑页面,这是显示在视图页面的父没有成为活动。这是我的视图页面

<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-bed"></i> Room Management <b class="fa fa-plus dropdown-plus"></b> </a>
        <ul class="dropdown-menu">
          <li class="<?php if($active_mn=='add_class') echo "active";?>"> <a href="<?php echo base_url()?>admin/add_class"> <i class="fa fa-caret-right"></i>Add Class</a> </li>
          <li class="<?php if($active_mn=='view_class') echo "active";?>"> <a href="<?php echo base_url()?>admin/view_class"> <i class="fa fa-caret-right"></i>View Class</a> </li>
          <li class="<?php if($active_mn=='add_rooms') echo "active";?>"> <a href="<?php echo base_url()?>admin/add_rooms"> <i class="fa fa-caret-right"></i>Add Rooms</a> </li>
          <li class="<?php if($active_mn=='view_rooms') echo "active";?>"> <a href="<?php echo base_url()?>admin/view_rooms"> <i class="fa fa-caret-right"></i>View Rooms</a> </li>
        </ul>
      </li>

从视图页面,我要编辑页面,这里是代码

 <td><a class="btn btn-success active" href="<?php echo base_url() ?>admin/edit_hostel/<?php echo $row->id ?>"> Edit </a> </td>

下面是我使用菜单激活的脚本

<script>
$(document).ready(function () {
 var url = window.location;
 $('ul.dropdown-menu a[href="' + this.location.pathname + '"]').parent().addClass('open active');
 $('ul.dropdown-menu a').filter(function() {
  return this.href == url;
 }).parent().parent().parent().addClass('open active');
 });
</script>
 <li class="dropdown <?php if($active_mn=='view_class'|| $active_mn=='view_rooms') echo "open active";?>"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-bed"></i> Room Management <b class="fa fa-plus dropdown-plus"></b> </a>
        <ul class="dropdown-menu">
          <li class="<?php if($active_mn=='add_class') echo "active";?>"> <a href="<?php echo base_url()?>admin/add_class"> <i class="fa fa-caret-right"></i>Add Class</a> </li>
          <li class="<?php if($active_mn=='view_class') echo "active";?>"> <a href="<?php echo base_url()?>admin/view_class"> <i class="fa fa-caret-right"></i>View Class</a> </li>
          <li class="<?php if($active_mn=='add_rooms') echo "active";?>"> <a href="<?php echo base_url()?>admin/add_rooms"> <i class="fa fa-caret-right"></i>Add Rooms</a> </li>
          <li class="<?php if($active_mn=='view_rooms') echo "active";?>"> <a href="<?php echo base_url()?>admin/view_rooms"> <i class="fa fa-caret-right"></i>View Rooms</a> </li>
        </ul>
      </li>

尝试包含伪选择器

 var url = window.location;
     $('ul.dropdown-menu a[href*="' + this.location.pathname + '"]').parent().addClass('open active').closest('li').addClass('open active');
 });