![](/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.