0

整个页面是主索引文件中的 PHP 包含。我应该将javascript放在主页上吗?或外部javascript文件?我引用 li 错误吗?

<ul>
<li class="about"><a href="index.php?about"><h1>about</h1></a></li>
<li class="team"><a href="index.php?team"><h1>team</h1></a></li>
<li class="training"><a href="index.php?training"><h1>training </h1></a></li>
<li class="courses"><a href="index.php?courses"><h1>courses</h1></a></li>
<li class="register"><a href="index.php?contact"><h1>contact</h1></a></li>
</ul>

<script type="text/javascript">
$("div").hover(
function () {
$(this).addClass("navhover");
},
function () {
$(this).removeClass("navhover");
}
); 
</script>

(外部 CSS 页面)

<script type="text/css">
#center .navhover {
   background:  url(images/active.jpg) no-repeat center center; 
}

#center .about {
 background: url(../images/about.jpg) no-repeat center center;
}
4

2 回答 2

1

为什么不跳过javascript并使用


li.about {
    background: url(../images/about.jpg) no-repeat center center;
}

li.about:hover {
    background:  url(images/active.jpg) no-repeat center center;
}

?

于 2010-10-28T11:19:39.993 回答
0
<script type="text/javascript" src="script.js"></script>
<script>
$(function(){
    $("ul li").hover(function () {
          $(this).addClass("navhover");
        },function () {
          $(this).removeClass("navhover");
        }
    ); 
});

</script>
<ul>
<li class="about"><a href="index.php?about"><h1>about</h1></a></li>
<li class="team"><a href="index.php?team"><h1>team</h1></a></li>
<li class="training"><a href="index.php?training"><h1>training </h1></a></li>
<li class="courses"><a href="index.php?courses"><h1>courses</h1></a></li>
<li class="register"><a href="index.php?contact"><h1>contact</h1></a></li>
</ul>

我自己试过了,效果很好

于 2010-10-28T10:09:06.340 回答