突出显示页面中的#部分-jQuery [英] Highlight a # section in a page - jQuery

查看:84
本文介绍了突出显示页面中的#部分-jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的html页面

I have a simple html page

<html>
<div id="d1>Content</div>
<div id="d2>Content</div>
<div id="d3>Content</div>
<a href="page.html#d1">D1</a> <a href="page.html#d2">D2</a> <a href="page.html#d3">D3</a>
</html>

我想用我的脚本突出显示所选的div

I want to highlight the selected div, with my script

<script>
var divID=window.location.href.split('#')[1];
$(divID).blahblahEffect;
<script>

问题是,这仅在我从X页面移至page.html时才有效,而在我单击任何链接后转到page.html后,它均不显示效果.

The problem is this works only the first time when i moved from X page to page.html, after going to page.html if i click on any Links it does not show the effect.

推荐答案

尝试

.highlight{ background-color :#FCFC9F; }

jQuery

$("a").click(function (e) {
   $('div').removeClass('highlight');
   var hashId=this.hash.substr(1);
   $('#'+hashId).addClass('highlight');           
   e.preventDefault();
});

这篇关于突出显示页面中的#部分-jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆