在新 window 上打开 table 行?
Open table row on new window?
我有一个 table 像:
<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 工作正常,可以点击并打开完整的行,但我想在新的 window 上打开 table 行 link 并选择大小。
我也有这个代码:
<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>
但它仅适用于定义的 table 单元格。
那么我如何在完整的行上创建 link 并且当用户单击该行时它将以定义的大小在新的 window 中打开?
除非我误解了你的问题,否则这样做就可以了(结合你的片段):
$('tr').click( function() {
window.open($(this).find('a').attr('href'),'targetWindow','toolbar=no,location=no,status=no,width=1000,height=600');
}).hover( function() {
$(this).toggleClass('hover');
});
1) 从 table 行中删除所有 onclick="
。现在应该是这样的:
<td><a href="http://www.example.com">Example</a></td>
2) 更改 jQuery 中的 .click(
。不要忘记 return false,否则链接将同时在新的 window 和当前的 window.
中打开
$('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;
})
您可以添加一个标志来区分行为。
<tr><td><a href="http://demo.com">demo</a></td></tr>
<tr data-flag="newWindow"><td><a href="http://demo2.com">demo2</a></td></tr>
然后
$('tr').click( function(e) {
if($(this).attr('data-flag') == "newWindow") {
window.open($(this).find('a').attr('href'),'targetWindow','toolbar=no,location=no,status=no,width=1000,height=600');
} else {
window.location = $(this).find('a').attr('href');
}
});
我有一个 table 像:
<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 工作正常,可以点击并打开完整的行,但我想在新的 window 上打开 table 行 link 并选择大小。
我也有这个代码:
<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>
但它仅适用于定义的 table 单元格。 那么我如何在完整的行上创建 link 并且当用户单击该行时它将以定义的大小在新的 window 中打开?
除非我误解了你的问题,否则这样做就可以了(结合你的片段):
$('tr').click( function() {
window.open($(this).find('a').attr('href'),'targetWindow','toolbar=no,location=no,status=no,width=1000,height=600');
}).hover( function() {
$(this).toggleClass('hover');
});
1) 从 table 行中删除所有 onclick="
。现在应该是这样的:
<td><a href="http://www.example.com">Example</a></td>
2) 更改 jQuery 中的 .click(
。不要忘记 return false,否则链接将同时在新的 window 和当前的 window.
$('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;
})
您可以添加一个标志来区分行为。
<tr><td><a href="http://demo.com">demo</a></td></tr>
<tr data-flag="newWindow"><td><a href="http://demo2.com">demo2</a></td></tr>
然后
$('tr').click( function(e) {
if($(this).attr('data-flag') == "newWindow") {
window.open($(this).find('a').attr('href'),'targetWindow','toolbar=no,location=no,status=no,width=1000,height=600');
} else {
window.location = $(this).find('a').attr('href');
}
});