我是Jquery的新手,想要弄清楚一些简单的事情。我有几个div点击各种链接时显示/隐藏。我希望能够为每个div提供固定链接,以便用户可以重新加载页面,而不必导航回他们正在查看的div。如何为不同的Jquery功能创建永久链接?
这是我到目前为止的jsfiddle。
(注:小提琴框架一直默认为Mootools的......请重置JQuery用户界面。)
我的页面的结构是这样的:
<div style="width:100%; height:40px; text-align:center;">
<a class="one" href="#">One</a>
<a class="two" href="#">Two</a>
<a class="three" href="#">Three</a>
<a class="four" href="#">Four</a>
</div>
<div id="one">One</div>
<div id="two">Two</div>
<div id="three">Three</div>
<div id="four">Four</div>
与jQuery脚本,看起来像这
$('a.one').click(function() {
$("#one").show('slide', {
direction: 'right'});
$("#two:visible, #three:visible, #four:visible").hide('slide', {
direction: 'left'});
});
$('a.two').click(function() {
$("#two:hidden").show('slide', {
direction: 'right'});
$("#one:visible, #three:visible, #four:visible").hide('slide', {
direction: 'left'});
});
$('a.three').click(function() {
$("#three:hidden").show('slide', {
direction: 'right'});
$("#one:visible, #two:visible, #four:visible").hide('slide', {
direction: 'left'});
});
$('a.four').click(function() {
$('#four:hidden').show('slide', {
direction: 'right'});
$("#one:visible, #two:visible, #three:visible").hide('slide', {
direction: 'left'});
});
将选定的选项卡放入URL的'#hash'中。然后让你的'document.ready'函数检查哈希并模拟相应的'a'上的点击。 – Barmar 2013-03-13 23:47:06
对不起,我对JQuery并不是很有经验......你能联系我一个如何完成的例子吗? – Emily 2013-03-13 23:59:02