Ctrl 加上单击 href=# 的问题

trouble with ctrl plus click of href=#

本文关键字:问题 href 单击 Ctrl      更新时间:2023-09-26

我正在使用Ember JS。我有一个<a>标签,单击该标签时,我从JS提交表单并导航到目标URL。一切正常。

为了显示指针图标,我在 HTML 上使用了href="#"。正如我多年来一直在做的那样。

现在,QA突然决定右键单击并在新选项卡中打开或CTRL单击。现在发生的情况是,打开一个新选项卡,其中包含如下所示的 URL。

www.something.com/index.html/#因为 href 是 #。

QA希望在新选项卡中看到目标页面

我有两个修复程序。

  1. 删除 href = # 并赋予 CSS 指针样式。使新选项卡不起作用
  2. 以某种方式打开选项卡并在新选项卡中进行表单发布。

2 可能吗?

与其"破解"a标签来获取指针,不如在CSS中使用cursor:pointer

演示:

div {
  height: 100px;
  width: 100px;
  display: inline-block;
  background: tomato;
  vertical-align:top;
}
.curs {
  cursor: pointer;
}
<div>no cursor</div>
<div class="curs">cursor</div>


由于您将其用于"提交表单",因此我建议使用

<input type="submit"/>

因为这将为您提交表格。

使用假标签!说,span.link

.link {color: #00f; text-decoration: underline; cursor: pointer;}
<span class="link">Is this a link?</span><br />
<a href="#">Is this a link?</a>

也许你可以采取不同的方法,只是尝试

function removeHashAndGo(){
   var url_wo_hash = this.hash.substr(1);
   window.open(url_wo_hash, "_blank"); //opens in a new window without #
}
$('#your_anchor_id').click(removeHashAndGo); //on click will call fn removeHashAndGo()