【发布时间】:2020-04-01 07:34:16
【问题描述】:
我已经尝试了许多线程,但到目前为止我无法让它工作。
我得到了可点击到新 URL 的行,但它在同一个选项卡中打开,this 有效。 但是,我希望 URL 在新选项卡中打开。我试过this 和this 但没有运气。
我什至尝试将第一个选项从window.location 修改为window.open,但它没有响应。
jQuery(document).ready(function($) {
$(".click-row").click(function() {
window.open($(this).data("href"));
});
});
<table>
<tbody>
<tr class='click-row' data-href="/Documents/files/file.pdf">
<td>Link to file</td>
</tr>
</tbody>
</table>
【问题讨论】:
-
试试这个:
window.open($(this).data("href"), "_blank"); -
试试这个
window.open($(this).data("href"), '_blank'); -
其实你的代码对我来说运行良好
-
@annoyingmouse 我以为我已经尝试了一百次,但显然没有。这很好用!非常感谢大家!
-
@BadPiggie 我在我使用的代码中真的找不到错误。不知道为什么它对我不起作用...但是感谢您的关注!
标签: javascript jquery html