简体   繁体   English

防止qtip2中的默认单击事件

[英]Preventing default click event in qtip2

I've created a link with a qtip2 tooltip using the following code: 我使用以下代码创建了一个带有qtip2工具提示的链接:

<a href="#" class="mylink">Show Tooltip</a>

$('.mylink').qtip({
  show: {event: 'click'}
});

When the link is clicked, the tooltip opens as expected, but the browser also navigates to /# , which causes the screen to scroll to the top. 单击链接后,工具提示将按预期方式打开,但是浏览器也会导航到/# ,这将导致屏幕滚动到顶部。 How can I prevent the original click event, without interfering with qtip? 如何在不干扰qtip的情况下防止原始点击事件?

Found the answer here . 这里找到答案。 Just bind to the click event of the link and use preventDefault . 只需绑定到链接的click事件并使用preventDefault

$('.mylink').qtip({
  show: {event: 'click'}
}).bind('click', function(event){ event.preventDefault(); return false; });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM