JQuery Accordion:单击标题时打开链接而不是向下滑动手风琴
更新:
$('#menu1').bind('accordionchangestart', function(e, ui)
{
console.log( 'accordionchangestart event triggered' );
e.preventDefault();
});
我尝试了上面的代码,我确实收到了控制台消息,但手风琴仍然向下滑动。有没有办法阻止手风琴在活动中滑落?
我尝试过 return false
和 e.stopImmediatePropagation()
。它们似乎都不能阻止手风琴滑落。
以下是我的手风琴 HTML:
<div id="menu1">
<div>
<h3><a href="#">Item 1</a></h3>
<div>
<a href="#">Item 1.1</a><br>
<a href="#">Item 1.2</a><br>
<a href="#">Item 1.3</a><br>
<a href="#">Item 1.4</a><br>
</div>
</div>
<div>
<h3><a href="item2.html">Item 2</a></h3>
<div></div>
</div>
<div>
<h3><a href="#">Item 3</a></h3>
<div>
<a href="#">Item 3.1</a><br>
<a href="#">Item 3.2</a><br>
<a href="#">Item 3.3</a><br>
<a href="#">Item 3.4</a><br>
</div>
</div>
</div>
我希望手风琴能够正常工作,除非标题链接不是 #
。例如,Item 2
的 href 为 item2.html
。在这种情况下,我希望它充当普通链接并打开页面。
UPDATE:
$('#menu1').bind('accordionchangestart', function(e, ui)
{
console.log( 'accordionchangestart event triggered' );
e.preventDefault();
});
I tried the code above, I do get the console message, but the accordion still slides down. Is there a way to stop the accordion from sliding down at the event?
I've tried return false
and e.stopImmediatePropagation()
. None of them appear to prevent the accordion from sliding down.
The following is my accordion HTML:
<div id="menu1">
<div>
<h3><a href="#">Item 1</a></h3>
<div>
<a href="#">Item 1.1</a><br>
<a href="#">Item 1.2</a><br>
<a href="#">Item 1.3</a><br>
<a href="#">Item 1.4</a><br>
</div>
</div>
<div>
<h3><a href="item2.html">Item 2</a></h3>
<div></div>
</div>
<div>
<h3><a href="#">Item 3</a></h3>
<div>
<a href="#">Item 3.1</a><br>
<a href="#">Item 3.2</a><br>
<a href="#">Item 3.3</a><br>
<a href="#">Item 3.4</a><br>
</div>
</div>
</div>
I want the accordion to work normally except when the header link is not #
. For example, Item 2
's href is item2.html
. In that case, I want it to function as a normal link, and open the page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是你可以做的:
HTML:
Javscript:
jsfiddle
That's what you can do:
The HTML:
The Javscript:
The jsfiddle
更改您的点击事件以包含如下内容:
change your click event to include something like this:
您能向我们展示您正在使用的插件吗?还是自制的?
如果它是一个插件,你可以去活动并说:
如果 href 与 # 不同,则转到链接。
例如
或类似的东西。如果没有 javascript 脚本,很难说。
Can you show us the plugin you are using? Or is it homemade?
If it's a plugin, you could go to the event and say:
if href different than # then go to link.
for Example
Or something like that. Hard to say without the javascript script.