Anchor URL访问时的Hightlight Anchor ID
编辑:
有人提到这在CSS中是可能的,所以我查了一下,这正是我需要的!
CSS
您需要使用:target伪类:
:target { background-color: #ffa; }
JS小提琴演示。
谢谢David Thomas的来源
还要感谢你的代码也是我需要的
我一直试图解决这个问题。
当有人通过以下url访问我的网页时:
http://jsfiddle.net/maNR5/show/#second
我希望带有id second的header元素用背景颜色突出显示。
这可能在JavaScript中? 谢谢你的任何提示。
试试这个:
var id=window.location.href.substring(window.location.href.lastIndexOf('/') + 1); $(id).css('background-color','red');
尝试使用:
var hash = window.location.hash; $('#'+hash).parent().css('background-color','red');
试试这个。 当你点击任何链接时改变它的颜色。 表示已访问。
$("h1").each(function(a,b){ $(this).find('a').click(function(){ console.log(this); $(this).css('color','#333399'); }); });