2012-05-31 55 views
1

我有5个链接在页面上,当我点击每个链接时,它会改变颜色,但只要马上ove我的光标并放置在页面的其他区域,焦点活动链接获取消失。所以我无法显示当前的链接状态。请告诉我如何解决切换css类为活动链接

+3

给一些代码PLZ – Onheiron

+0

http://www.hicksdesign.co.uk/journal/highlighting-current-page-with-css – Jawad

+0

HTTP://www.mstudiostalk .com/2008/03/11/pure-css-to-display-the-active-page-in-the-navigation/ – Jawad

回答

3

的Html

<tr> 
<td> 
    <a href="#" class="linkbold">Basic2</a> 
</td> 
</tr> 
<tr> 
<td> 
    <a href="#" class="linkbold">Basic3</a> 
</td> 
</tr> 
<tr> 
<td> 
    <a href="#" class="linkbold">Basic4</a> 
</td> 
</tr> 

的CSS

.linkbold{ color:#0066FF; font-family:Tahoma; font-size:11px; text-decoration:none; font-weight:bold !important; } 
.active { color: red; } // define any color for active class 

// you can use css shorthand for font property 
.linkbold { font: bold 11px Tahoma, sans-serif; color:#0066FF; } 

如果您想了解更多关于css shorthand

jQuery的

$('a.linkbold').on('click', function(){ 
    $('a.linkbold').removeClass('active'); // remove any active class 
    $(this).addClass('active'); // and then add active class for clicked element. 
});​ 

Working example here

+0

它可以用javascript代替jquery吗? – Dhananjay

+0

作为标题说“[jquery](http://jquery.com/)是一种新的JavaScript库”。 – agriboz

+0

是的,但在我的应用程序中,我使用的是extjs,我无法在js文件中插入jquery。 – Dhananjay

-2
<html> 
<head> 
    <style type="text/css"> 
     a:link {color:blue;} 
     a:visited {color:red;} 
     a:hover {color:green;} 
    </style> 
</head> 
<body> 
    <a href="#">first</a> 
    <br/> 
    <a href="#">second</a> 
</body> 
</html> 
+0

谢谢,但我有5个链接,这意味着当我点击下一个链接上一个链接应该得到它的原始状态。 – Dhananjay