<script language="javascript">
$(document).ready(function(){
var currentLocation = location.pathname;
alert(currentLocation);
// if (currentLocation == "media-gallery/pictures"){
// $("#menu-item-140").addClass("active");
// }
});
</script>
<script language="javascript">
$(document).ready(function(){
var currentLocation = location.pathname;
// alert(currentLocation);
if (currentLocation == "/media-gallery/pictures"){
$("#menu-item-140").addClass("active");
}
});
</script>
:)
编辑:
澄清一下,假设您的文件位于http://example.com/test/blank.php ,此代码已经过全面测试并且可以正常工作。请注意前导斜线。
<style>
.active{
background-color: red;
}
</style>
<div id="menu-item-140">Make me red</div>
<script language="javascript">
$(document).ready(function(){
var currentLocation = location.pathname;
alert(currentLocation);
if (currentLocation == "/test/blank.php"){
$("#menu-item-140").addClass("active");
}
});
</script>