![](/img/trans.png)
[英]jQuery links not clickable but i can right click open in new tab?
[英]Clickable rows in seperate HTML file to open different links in a new tab
我正在使用jQuery,并且在单独的HTML文件中的表中有几行。 单击时,每一行都成功重定向到本地HTML文件。 (使用window.location)
我正在努力实现的目标
我要完成的工作是,当我单击本地HTML文件的行时,它在新选项卡中而不是当前选项卡中打开 。
我知道,如果这是<a>
锚点,这将很容易实现。
我的问题
window.open
在这种特定情况下不起作用(至少是我尝试的方式),并且应用target="_blank"
将是无用的,因为这不是<a>
标记。 这是一个表格行。
我尝试过的
jQuery的:
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.open = $(this).data("href");
});
});
单独的HTML文件:
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>thead1</th>
<th>thead2</th>
<th>thead3</th>
<th>thead4</th>
<th>thead5</th>
<th>thead6</th>
</tr>
</thead>
<tbody>
<tr class="clickable-row" data-href="\path\index.html">
<td>tcell1</td>
<td>tcell2</td>
<td>tcell3</td>
<td>tcell4</td>
<td>tcell5</td>
<td>tcell6</td>
</tr>
<tr class="clickable-row" data-href="\path\differentindex.html">
<td>tcell1</td>
<td>tcell2</td>
<td>tcell3</td>
<td>tcell4</td>
<td>tcell5</td>
<td>tcell6</td>
</tr>
</tbody>
</table>
</div>
为了大致了解我的DOM结构,我指的是带有includeHTML函数的单独HTML文件。
我读过的资料
我假设我无法使用window.open
在阅读对象的工作方法之后尝试的方式。
我读过。开和.location之间的差别在这里 。 但是,我不确定何时使用什么。
你有尝试过吗?
window.open(
'your url',
'_blank' // <- This is what makes it open in a new window.
);
或者,您可以创建定位标记并进行点击事件
$("body").append('<a id="link" href="your url" target="blank"> </a>');
$( '#链接')[0]。点击();
$( ".clickable-row" ).each(function(index) {
$(this).on("click", function(){
window.open($(this).data("href"),'_blank');
});});
尝试这个
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.open($(this).data("href"),'_blank');
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.