所以我试图根据与li中a标签的href匹配的URL向li添加一个类。我当前的代码正在为每个 li 添加一个类,但我需要尝试让它只添加到包含匹配标签的 li 中。这有任何意义吗?任何帮助将不胜感激。
我的代码:
<div id="admin-action-menu" class="links">
<div id="cat_settings" class="cat_menu row-fluid">
<ul role="menu" >
<? if (($user->type_id == 1) || ($user->type_id == 2)) { ?>
<li>
<div class="icon system-settings">
</div>
<div class="action-text">
<span>
System Settings
</span>
</div>
<a href="/admin/system_settings"></a>
</li>
<? } ?>
<? if (($user->type_id == 1) || ($user->type_id == 2)) { ?>
<li>
<div class="icon email-settings">
</div>
<div class="action-text">
<span>
Email Settings
</span>
</div>
<a href="/admin/email_settings"></a>
</li>
<? } ?>
</ul>
</div>
<div id="cat_people" class="cat_menu row-fluid">
<ul role="menu" >
<? if ($user->type_id == 1) { ?>
<li>
<div class="icon system-admins">
</div>
<div class="action-text">
<span>
System Admins
</span>
</div>
<a href="/admin/admin_list"></a>
</li>
<? } ?>
<? if ($user->type_id == 1 || $user->type_id == 2) { ?>
<li>
<div class="icon company-admins">
</div>
<div class="action-text">
<span>
Company Admins
</span>
</div>
<a href="/admin/company_admin_list"></a>
</li>
<? } ?>
</ul>
</div>
</div>
<script>
$('.cat_menu li').each(function(){
var link = $(this).data('href');
var url = window.location.href;
if ( link = url ) {
$(this).addClass('yuuuuup');
} else {
$(this).addClass('nooooope');
}
});
</script>