我需要在codeigniter中为我的侧栏菜单活动类使用JavaScript
嗨,我是codeigniter的新手这是我的观点我需要在codeigniter中为我的侧栏菜单活动类使用JavaScript,javascript,php,jquery,css,codeigniter,Javascript,Php,Jquery,Css,Codeigniter,嗨,我是codeigniter的新手这是我的观点 在此处输入代码 创建主程序“> 创建程序 myprogram“> 我的节目 <li class="dropdown"> <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"> My Profile
在此处输入代码
创建主程序“>
创建程序
myprogram“>
我的节目
<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>
我的
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{
}
});
您必须在
li
中给出href
。请参考以下答案:
// 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{
}
});