我在无序列表中有一个导航。悬停时这些图像应该会关闭
整个页面是一个 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;
}
The whole page is a PHP include inside of a main index file. Should I be placing the javascript on the main page? or an external javascript file? Am I referencing the li wrong?
<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>
(external CSS page)
<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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不直接跳过 javascript 并使用 呢
?
Why not just skip the javascript and use
?
我自己刚刚尝试过,效果非常好
i just tried this myself and it worked perfectly