我需要 JavaScript 作为我的侧边栏菜单活动类在 codeigniter 中
i need JavaScript for my sidebar menu active class in codeigniter
嗨,我是编码点火器的新手,这是我的观点
enter code here
create_main_program> 创建程序
我的程序"> 我的程序
<li class="dropdown">
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
My Profile
<span class="caret"></span>
<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-user"></span>
</a>
<ul class="dropdown-menu forAnimate" role="menu">
<li>
<a href="<?php echo base_url(); ?>viewprofile">View Profile</a>
</li>
<li>
<a href="<?php echo base_url(); ?>editprofile">Edit Profile</a>
</li>
</ul>
</li>
<li>
<a href="<?php echo base_url(); ?>password">
Change Password
<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-cog"></span>
</a>
</li>
<li >
<a href="javascript:;">
Premium Listing
<span style="font-size:16px;" class="pull-right hidden-xs showopacity fa fa-usd"></span>
</a>
</li>
<li >
<a href="javascript:;">
Support
<span style="font-size:16px;" class="pull-right hidden-xs showopacity fa fa-question-circle"></span>
</a>
</li>
<li >
<a href="<?php echo base_url(); ?>homelogout" onclick="return confirm('Are you sure to logout?');">
Logout
<span style="font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-off"></span>
</a>
</li>
</ul>
'
我的JavaScript是
$( document ).ready(function(){
var pathname = window.location.href; //the url which displayed in the address bar. Ex. http://www.google.com/CreateUser
var partsArray = pathname.split('/');
var url = '/' + partsArray[4]; // after splitting the url the array will contains each part of the array starting from index 0
alert(url);
var a_s = $('li');
a_s.removeClass('active'); //This removes active class of the previous li element
$('li a').each(function () // loop through all li element available in the page
{
// alert($(this).attr('href'));
if ($(this).attr('href') == url) //check whether the part of the URL and href of the current li elment is matching or not
{
$(this).addClass('active'); // add active class to the li element if it is matched
} else{
}
});
});
我的sidebar.php
包含在所有页面中,因此请帮助我激活侧边栏选择菜单。
尝试用这个改变循环
// loop the li not a
$('li').each(function () // loop through all li element available in the page
{
// alert($(this).attr('href'));
//assign a to variable link
var link = $(this).find('a');
if (link.attr('href') == url) //check whether the part of the URL and href of the current li elment is matching or not
{
link.addClass('active'); // add active class to the li element if it is matched
} else{
}
});
相关文章:
- 悬停下拉菜单即使在鼠标移出后也保持活动状态
- 将js添加到wordpress中以突出显示css活动菜单
- 菜单栏class=活动引导程序主题无法正常工作
- 如何使活动菜单项具有突出显示样式
- 活动菜单 部分高度问题
- 无法设置活动菜单元素的样式
- 使用 javascript 在 Joomla 中获取活动菜单 itemid
- 使用 jQuery 将类添加到活动菜单
- jQuery和活动菜单项 - 什么是最好的
- HTML/CSS当前活动菜单不显示活动
- jquery活动菜单在点击链接后丢失
- jQuery保持活动菜单项高亮显示
- 简化一个活动菜单jQuery代码
- 如何记住活动菜单
- 如何用另一个活动菜单突出显示另一个菜单
- 添加活动菜单类
- 锚菜单不同的css在活动菜单
- 在AngularJS中高亮当前活动菜单的正确方法是什么?
- 如何在滚动后自动更改活动菜单(菜单导航)?
- 带有三角形选择器的CSS活动菜单