造型li包含当前a [英] styling li containing current a
本文介绍了造型li包含当前a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码有什么问题:
what is wrong with this code:
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script>
$(function(){
$('li').each(function() {
var href = $(this).find('a').attr('href');
if (href == window.location.pathname) {
$(this).addClass('current');
}
});
});
</script>
.current {
background:red !important;
color:blue !important;
}
推荐答案
( function (){
(' li')。each( function (){
var href =
('li').each(function() { var href =
( this )。find(' a')。attr(' HREF'跨度>);
if (href == window 。 location .pathname){
(this).find('a').attr('href'); if (href == window.location.pathname) {
这篇关于造型li包含当前a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文