在新标签中打开锚链接.链接将在新标签中附加现有网址

Vel*_*aga 0 javascript jquery struts backbone.js underscore.js

我的下划线模板中有以下代码

<li><a href="#" onclick="window.open('http://www.weather.com','_blank')"><%= element.description%></a></li>
Run Code Online (Sandbox Code Playgroud)

和我的currentPage网址是

    "http://localhost:9060/SampleApp/SampleServlet/Logon"
Run Code Online (Sandbox Code Playgroud)

当我点击锚点时,它会在新标签页中打开链接,但它会附加当前网址ex)

    "http://localhost:9060/SampleApp/SampleServlet/Logon/www.weather.com"
Run Code Online (Sandbox Code Playgroud)

如何使用chrome中的新选项卡打开此页面?为什么当前URL会与anchorURL一起追加?

Ion*_*zău 5

由于元素是一个a元素,您只想在新选项卡中打开链接,因此使用srctarget属性:

<li>
  <a href="http://www.weather.com" target="_blank">
   <%= element.description%>
  </a>
</li>
Run Code Online (Sandbox Code Playgroud)