【问题标题】:<tr> as link + target="_blank" [duplicate]<tr> 作为链接 + target="_blank" [重复]
【发布时间】:2017-01-03 07:15:26
【问题描述】:

我的 HTML + jQuery 代码有问题。

我想将我的表格行设置为链接到某个东西,但我不知道如何添加 target="_blank" 属性。谁能帮我解决这个问题?

HTML

<tr class='clickableRow' data-url="http://tbc.designcrown.co.uk/go/siteground">
    <td>Sample</td>
</tr>

jQuery

jQuery(document).ready(function($) {
  $(".clickableRow").click(function() {
        window.document.location = $(this).data('url');
  });
});

【问题讨论】:

  • 您可以使用window.open,但最好只使用适当的链接——可能围绕每个&lt;td&gt;的内容。
  • @ShaifulIslam 为什么? data() 方法工作得很好,比使用 attr() 更灵活

标签: jquery html html-table


【解决方案1】:

除了实际的&lt;a /&gt; 标记外,您不能在任何地方使用目标属性。你可以做的是调用window.open() 来创建一个弹出窗口。

例如:

window.open('http://www.stackoverflow.com/','StackOverflow','resizable=1,status=1,menubar=1,toolbar=1,scrollbars=1,location=1,directories=1,width=350,height=350,top=60,left=60')

这里有一个生成相应 JS 的工具:http://www.ricocheting.com/code/javascript/html-generator/popup-window

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多