JavaScript 和 href

发布于 2024-12-08 13:12:01 字数 261 浏览 1 评论 0原文

假设我在最后一个 div 之后有以下下拉菜单,单击后会出现一个下拉菜单。

<div id="test"> <a href="clickthrough.php">Arrow</a> </div>

我希望用户能够单击此元素并出现下拉列表,而且如果他单击中间也能够直接在新选项卡中打开此链接。换句话说,我想阻止默认操作 onclick 但仍然在悬停或其他情况下显示元素的链接。

谢谢

Let's suppose that I have the following dropdown after the last div, a dropdown menu appears once he clicks.

<div id="test"> <a href="clickthrough.php">Arrow</a> </div>

I want the user to be able to click on this element and the dropdown appear but also if he mid clicks to be able to open this link directly in a new tab. In other words I want to prevent the default action onclick but still show the link of the element on hover or whatever.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浪漫之都 2024-12-15 13:12:01

你可以做

<div id="test"> <a href="clickthrough.php" onclick="FunctionForOpeningLink();return false;">Arrow</a> </div>

you can do

<div id="test"> <a href="clickthrough.php" onclick="FunctionForOpeningLink();return false;">Arrow</a> </div>
蒲公英的约定 2024-12-15 13:12:01

使用 jquery 1.7+

$('#test a').on('click', function (e) {
  if (e.which < 2) { // left mouse button
    e.preventDefault();
    // and code to show dropdown
  }
});

with jquery 1.7+

$('#test a').on('click', function (e) {
  if (e.which < 2) { // left mouse button
    e.preventDefault();
    // and code to show dropdown
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文