我有这个代码
<div id="accordion">
<h3>Section 1 <a href="www.google.com">Google</a> </h3>
<div>
Text...
</div>
<h3>Section 2</h3>
<div>
Text...
</div>
</div>
我无法开始工作<a>
<h3>
内的标签因为 jQuery Accordion 展开/折叠事件发生了。
如何避免该事件 <a>
从 Accordion 事件中独立工作?
最佳答案
您可以发布您正在使用的 jquery 插件的代码或链接吗?听起来 jquery 代码正在运行函数 preventDefault() 并且 a 标记正在冒泡并触发该事件。
你可以像这样在 anchor 上包装一个事件
$('#accordian').on('click', 'a', function(e) {
e.stopPropogation();
window.location.href = this.href;
});
如果您在 anchor 标记内添加元素,请小心使用此代码。如果您单击该元素,它不会成为启动事件的 anchor ,它会具有 href 属性。
关于javascript - 如何忽略嵌套 <a> 的 jQuery Accordion 点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31077735/