<script>
$(document).ready(function() {
// store url for current page as global variable
current_page = document.location.href
// apply selected states depending on current page
if (current_page.match(/home/)) {
$("#krymson_nav ul li:eq(0)").addClass('active');
} else if (current_page.match(/dashboard/)) {
$("#krymson_nav ul li:eq(1)").addClass('active');
} else if (current_page.match(/content/)) {
$("#krymson_nav ul li:eq(2)").addClass('active');
} else if (current_page.match(/modules/)) {
} else { // don't mark any nav links as selected
$("#krymson_nav ul li")开发者_如何学运维.removeClass('selected');
};
});
</script>`
HTML:
<div id="krymson_nav">
<ul>
<li class="active"><a href="http://blackboarddev.com/new/modules/krymson/dashboard.php">Dashboard</a></li>
<li><a href="http://blackboarddev.com/new/modules/krymson/content.php">Content</a></li>
</ul>
</div>
In one line:
$("a[href='" + document.location.href + "']").closest('li').addClass('active');
精彩评论