4

我有一个用作图片库的 URL。在这个 URL 上是一个大拇指div(为简洁起见,我只显示四个大拇指):

 <div id="thumbs">
 <img src="graphics/thumbs/01.jpg" width="190" height="190" class="thumb objects" id="project01" />
 <img src="graphics/thumbs/08.jpg" width="190" height="190" class="thumb web" id="project08" />
 <img src="graphics/thumbs/14.jpg" width="190" height="190" class="thumb freehand" id="project14"/>
 <img src="graphics/thumbs/04.jpg" width="190" height="190" class="thumb freehand objects" id="project04" /></div>

和一个空div#content

<div id="content"></div>

和一个隐藏的div#preload

 <div id="preload">
<span id="project01_content"><img src="graphics/010.jpg" /></span>
<span id="project02_content"><img src="graphics/022.jpg" /><img src="graphics/021.jpg" /><img src="graphics/023.jpg" /><img src="graphics/020.jpg" /></span>
<span id="project03_content"><img src="graphics/030.jpg" width="450" height="600" /><img src="graphics/031.jpg" width="450" height="600" /></span>
<span id="project04_content"><img src="graphics/040.jpg" width="775" height="600" /><img src="graphics/041.jpg" width="775" height="600" /></span></div>

我的 jQuery 使用单击缩略图的 ID 到clone()相应图像中的图像,并使用该方法span将它们放入。它工作得很好。现在,我想返回并已经填写了 Project 01。#contenthtml()mysite.com/#project01#content

如何给每个图像一个哈希 URL 来调用相同的 jQuery 状态?

4

1 回答 1

3

您可以在页面加载后立即单击该拇指,并且您的当前代码应该执行,如下所示:

$(function() {
  if(window.location.hash.indexOf('project') > -1)
    $(window.location.hash).click();
});

这将使用您的示例 URL 中的属性window.location.hash......"#project01"所以它已经是一个#ID选择器,我们只是检查它是否是我们关心的哈希,然后使用该选择器来触发一个.click(). 只需确保它您当前的拇指点击处理程序绑定后运行。

于 2010-08-18T12:05:07.150 回答