我不知道这种行为会不会很奇怪。突出显示由链接的焦点设置。单击其他位置删除焦点和样式(突出显示)。
要更改此行为,请添加一个 css 类以链接焦点(并删除此类以获取先前的焦点链接)。为这个 CSS 类赋予与高亮类相同的样式。
示例 html:
<div class="dropdown clearfix">
<ul style="display: block; position: static; margin-bottom: 5px; *width: 180px;" aria-labelledby="dropdownMenu" role="menu" class="dropdown-menu">
<li><a href="#1" tabindex="-1">Action</a></li>
<li><a href="#2" tabindex="-1">Another action</a></li>
<li><a href="#3" tabindex="-1">Something else here</a></li>
<li class="divider"></li>
<li><a href="#4" tabindex="-1">Separated link</a></li>
</ul>
</div>
要添加的类的 css(称为焦点):
.dropdown-menu > li > a.focused
{
color: #ffffff;
text-decoration: none;
background-color: #0081c2;
background-image: -moz-linear-gradient(top, #0088cc, #0077b3);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0077b3));
background-image: -webkit-linear-gradient(top, #0088cc, #0077b3);
background-image: -o-linear-gradient(top, #0088cc, #0077b3);
background-image: linear-gradient(to bottom, #0088cc, #0077b3);
background-repeat: repeat-x;
outline: 0;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0077b3', GradientType=0);
}
javascript:
$('.dropdown li a').focus(function(){
$('.dropdown li a').removeClass('focused');
$(this).addClass('focused');
});
示例/演示: http ://bootply.com/66106