获取活动链接Jquery上的折叠菜单&;独自创立
我需要得到折叠的菜单上点击一个链接,该链接将有一个类命名为'积极' 只有当我单击与url中的id和uri匹配的主链接时,我才能得到这个结果。 但单击链接内部的链接时,菜单将崩溃 主要问题是,在jquery中,我无法获取警报并检查是否应用了类或id获取活动链接Jquery上的折叠菜单&;独自创立,jquery,codeigniter,Jquery,Codeigniter,我需要得到折叠的菜单上点击一个链接,该链接将有一个类命名为'积极' 只有当我单击与url中的id和uri匹配的主链接时,我才能得到这个结果。 但单击链接内部的链接时,菜单将崩溃 主要问题是,在jquery中,我无法获取警报并检查是否应用了类或id <script type="text/javascript"> if($('#subcategoryactive').length){ alert('Active'); } if( $('.list
<script type="text/javascript">
if($('#subcategoryactive').length){
alert('Active');
}
if( $('.list-subgroup-item active').length )
{
alert('Active');
}
</script>
<h4>Categories</h4>
<div class="list-group categories">
<?php foreach($categories as $category): ?>
<a href="<?php echo site_url() . '/products/catalog_list/' . $category['id'] ; ?>" class="list-group-item"><?php echo $category['name']; ?><span class="glyphicon glyphicon-chevron-right"></span></a>
<div id="collapseOne" class="panel-collapse collapse <?php if($category['id'] == $this->uri->segment(3)){ echo 'in';}else{ echo 'out';} ?>">
<?php foreach($category['sub_categories'] as $subcategory): ?>
<div class="list-subgroups">
<a id="subcategory<?php if($subcategory['id'] == $this->uri->segment(3)){ echo 'active';} ?>" href="<?php echo $subcategory['id']; ?>" class="list-subgroup-item <?php if($subcategory['id'] == $this->uri->segment(3)){ echo 'active';} ?>"><?php echo $subcategory['name']; ?></a>
</div>
<?php //endif; ?>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
如果($('#子类别活动')。长度){
警报(“活动”);
}
if($('.list子组项活动').length)
{
警报(“活动”);
}
类别
首先,您需要使用dom ready事件包装jquery代码,并在
方法上使用尝试将jquery代码更改为以下内容,然后告诉我
<script type="text/javascript">
$(function(){ // add this
$('div.list-group').on('click', 'a.active', function(){
//if($('#subcategoryactive').length) {
// alert('Active');
//}
//if( $('.list-subgroup-item active').length ) {
alert('Active');
//}
});
});
</script>
$(函数(){//添加此
$('div.list-group')。在('click','a.active',function()上{
//如果($('#子类别活动')。长度){
//警报(“活动”);
//}
//if($('.list子组项活动').length){
警报(“活动”);
//}
});
});
就是这样,它打开所有菜单并保持打开状态,thx Moes