【发布时间】:2016-02-18 18:48:54
【问题描述】:
我一直在尝试使单击链接时,颜色停留在那里,不仅是在鼠标单击链接时(如果鼠标失去对链接的关注,颜色将恢复到正常状态)。
当你想问这个问题时,这个网站的颜色会停留在问问题标签上。
这是我尝试的 JSFiddle 上的代码示例:
HTML
<ul id="parentExample" style="display: block;">
<asp:Repeater runat="server" ID="uiMenuList">
<ItemTemplate>
<li id="childExample">
<a id="uiMenuText" href="http://www.google.com" target="_blank" runat="server">First Menu</a>
<a id="uiMenuText" href="http://www.google.com" target="_blank" runat="server">Second Menu</a>
<a id="uiMenuText" href="http://www.google.com" target="_blank" runat="server">Third Menu</a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
JavaScript
$(document.ready(function() {
var $h3s = $('li').click(function() {
$h3s.removeClass('active');
$(this).addClass('active');
});
}));
CSS
.active {
background: none;
color: #FFC000;
border: 0px;
margin-top: -3px;
margin-right: auto;
margin-left: auto;
}
#parentExample li#childExample a {
background: none;
color: black;
border: 0px;
margin-top: -3px;
margin-right: auto;
margin-left: auto;
}
#parentExample li#childExample a:hover {
background: none;
color: red;
border: 0px;
margin-top: -3px;
margin-right: auto;
margin-left: auto;
}
#parentExample li#childExample a:active {
background: none;
color: #FFC000;
border: 0px;
margin-top: -3px;
margin-right: auto;
margin-left: auto;
}
#parentExample li#childExample a:selected {
background: none;
color: #FFC000;
border: 0px;
margin-top: -3px;
margin-right: auto;
margin-left: auto;
}
以下是上述代码的示例: JS Fiddle
任何帮助将不胜感激
谢谢
【问题讨论】:
-
您的设置不正确。您的代码应该是
$(function() { var $h3s = $('li').click(function() { console.log($h3s); $h3s.removeClass('active'); $(this).addClass('active'); }); });并将站点设置为加载 jQuery。
标签: javascript html css asp.net