如何定义默认情况下其中一个菜单项处于活动状态?
/* CSS */
ul#menu a.active, ul#menu a:focus {
outline-style: none;
color: #AA0000;
font-weight: bold;
text-decoration: underline;
}
/* HTML */
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="scripts/hormenu_selector.js"></script>
</head>
<body>
<div id = "menu">
<ul>
<li><a href="#" class="active">Test1</a></li>
<li><a href="#">Test2</a></li>
</ul>
</div>
</body>
</html>
/* HORMENU_SELECTOR.JS */
$(document).ready(function() {
$('#menu ul li a').each(function() {
var path = window.location.href;
var current = path.substring(path.lastIndexOf('/'));
var url = $(this).attr('href');
if (url == current) {
$(this).addClass('active');
};
});
});