【发布时间】:2013-10-16 22:28:37
【问题描述】:
我创建了一个基本的jsFiddle 来举例说明我正在做什么。 (我正在使用 Wordpress 和 Bootstrap。)
我的问题:
每个菜单项都有一个 href 引用我的 Wordpress 后端中的一个页面。当您单击一个菜单项时,会加载一个新页面并忽略 jQuery 函数。所以我用preventDefault 忽略了href。现在,当我单击不同的菜单项时,没有从后端加载任何新内容,因为 preventDefault 已禁用原始 href。
有没有办法解决这个问题?因此,如果您单击菜单项,则 div #content 会向右滑动,其中包含该页面的实际内容。
JS
$("#menu-hoofdnavigatie li a").click(function (event) {
event.preventDefault();
var effect = 'slide', // Set the effect type
options = { direction: 'left' }, // Set the options for the effect type chosen
duration = 700; // Set the duration
$('#content').toggle(effect, options, duration);
});
HTML
<section id="content" class="col-lg-5 height-inherit no-padding">
<div class="content-inner">
<a class="closure pull-right">X</a>
<h1><span>_ </span><?php the_title(); ?></h1>
<article>
<?php the_content(); ?>
</article>
<div class="border"></div>
<a class="see-more" href="">Bekijk mijn realisaties <i class="icon-long-arrow-right"></i></a>
</div>
</section>
【问题讨论】:
-
具体的问题是什么?您想在单击一个链接时显示内容,当您单击另一个链接时隐藏以前的内容并根据此链接显示内容?
-
没错。如果可能,也无需重新加载页面。
标签: jquery html wordpress toggle preventdefault