我有一个像这样的表:
<tr>
<td><a href="http://www.example.com/">example</a></td>
<td>another cell</td>
<td>one more</td>
</tr>
我正在使用这个 Javascript 代码:
$('tr').click( function() {
window.location = $(this).find('a').attr('href');
}).hover( function() {
$(this).toggleClass('hover');
});
这个 Javascript 工作正常,使完整的行可点击并打开,但我想在新窗口上以选定的大小打开表格行链接。
我也有这个代码:
<td><a href="www.example.com" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,width=1000,height=600'); return false;">Example</a></td>
但它仅适用于定义的表格单元格。 那么,如何在完整的行上创建链接,并且当用户单击该行时,它将在具有定义大小的新窗口中打开?
最佳答案
1) 从表格行中删除所有 onclick="
。现在应该如下所示:
<td><a href="http://www.example.com">Example</a></td>
2) 更改 jQuery 中的 .click(
。不要忘记返回 false,否则链接将在新窗口和当前窗口中打开。
$('tr, tr a').click( function() {
window.open($(this).find('a').attr('href'),'targetWindow','toolbar=no,location=no,status=no,width=1000,height=600');
return false;
})
关于javascript - 在新窗口中打开表格行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31200955/