【发布时间】:2014-05-13 13:48:24
【问题描述】:
我正在尝试为希望同时在菜单底部和右上角的徽标上方显示“联系我们”页面的人设计一个网站。
因此这里是客户端代码:
这是徽标上方的顶部菜单:
<ul class="topnavigation" style="width:1000px; border-bottom-style: none; height: 40px;">
<li class="highlight" style="width:100px; height: 40px; font-family:Calibri; float:right;"><a href="ContactUs.aspx">Contact Us</a></li>
<li style="width:100px; height:40px; font-family:Calibri; border-left:1px solid white; border-right:1px solid white; float:right;"><a href="StartPage.aspx">Home</a></li>
</ul>
这是标志下的菜单:
<ul class="navigation" style="width:1000px; height:40px; border-bottom:none;">
<li style="width:150px; font-family:Calibri; height: 40px; border-right:1px solid white;"><a href="AboutUs.aspx">About Us</a></li>
<li style="width:150px; font-family:Calibri; border-right:1px solid white; height: 40px;"><a href="Application.aspx">Applications</a></li>
<li style="width:200px; font-family:Calibri; border-right:1px solid white; height: 40px;"><a href="FeaturesAndBenefits.aspx">Features and Benefits</a></li>
<li style="width:200px; font-family:Calibri; border-right:1px solid white; height: 40px;"><a href="TechnicalSpecs.aspx">Technical Specs</a></li>
<li style="width:150px; font-family:Calibri; border-right:1px solid white; height: 40px;"><a href="ContactUs.aspx">Contact</a></li>
<li style="width:145px; font-family:Calibri; border-right:none; height: 40px;"><a href="Recognition.aspx">Recognition</a></li>
</ul>
为了突出显示用户选择的页面,我使用了一些 javascript(我最近一直在尝试学习)和 CSS
JavaScript:
$(document).ready(function () {
var str = location.href.toLowerCase();
$('.topnavigation li a').each(function () {
if (str.indexOf(this.href.toLowerCase()) > -1) {
$("li.highlight").removeClass("highlight");
$(this).parent().addClass("highlight");
}
});
$('.navigation li a').each(function () {
if (str.indexOf(this.href.toLowerCase()) > -1) {
$("li.highlight").removeClass("highlight");
$(this).parent().addClass("highlight");
}
});
});
CSS:
ul.navigation
{
margin: 0px;
padding: 0px;
list-style: none;
background-color:#0071BB;
height:34px;
border-bottom:none;
}
ul.navigation li
{
float: left;
position: relative;
top: 0px;
left: 0px;
}
ul.navigation li a:last-child{}
ul.navigation a
{
color:white;
display: block;
padding: 8px 8px;
text-decoration: none;
}
/*background color of LI*/
ul.navigation li.highlight
{
background:Darkblue;
}
/*Text color for A*/
ul.navigation li.highlight a
{
color:white;
}
ul.navigation li:hover
{
color:white;
background-color:darkblue;
background: darkblue;
}
a, a:visited
{
color:#000;
}
ul.topnavigation
{
margin: 0px;
padding: 0px;
list-style: none;
background-color:#0071BB;
height:34px;
border-bottom:none;
}
ul.topnavigation li
{
float: left;
position: relative;
top: 0px;
left: 0px;
}
ul.topnavigation li a:last-child{}
ul.topnavigation a
{
color:white;
display: block;
padding: 8px 8px;
text-decoration: none;
}
/*background color of LI*/
ul.topnavigation li.highlight
{
background:Darkblue;
}
/*Text color for A*/
ul.topnavigation li.highlight a
{
color:white;
}
ul.topnavigation li:hover
{
color:white;
background-color:darkblue;
background: darkblue;
}
使用此实现,如果用户单击任何页面,它会突出显示该页面。但如果他们点击右上角的联系我们,只会突出显示底部菜单中的联系我们,而不是顶部菜单。我发现这很奇怪,这对我来说本身就是一个问题,因为我希望它突出显示顶部而不是底部。 (如果有人也能回答这个问题,我将不胜感激 - 因为我看不出它是如何识别它的)。
那么,我怎样才能同时突出显示顶部联系人页面导航和底部联系人页面导航。我假设这将使用 java 脚本而不是 C# 代码来完成。
我试图将两者结合起来,例如
$('.navigation li a' & '.topnavigation li a').each(function () {
但意识到这可能行不通,因为它正在编制索引。虽然我不确定。我试图将它们设置为“如果等效”,因此如果两个 href 相同,那么它将突出显示它们。我所做的一切都没有奏效(尽管有趣的是我得到了一些突出其他导航的奇怪结果)。
那么,有什么建议吗?指出我正确的方向?我没有看到的东西或如何做到这一点?这是否需要在 C# 中完成? JavaScript 能做到吗?
请告诉我。这是我提出的第一个问题,所以我对此感到沮丧。
【问题讨论】:
-
你听说过fiddle吗?
-
@KingKing 之类的。我对这一切都很陌生。但是,与我在 VS 2013 上测试和运行它相比,小提琴有什么意义呢?还是我不懂小提琴?
-
我认为他是在建议您设置一个小提琴来演示该问题,以便人们可以帮助您解决它。
-
+1 KingKing 因为我没有用过小提琴,这很漂亮。我在想这是别的东西。
-
前往jsfiddle.net 并设置测试。
标签: c# javascript jquery html css