我正在尝试使用JQuery使表行可单击并重定向到隐藏在第一个单元格中的URL.我在表的最后一列中有一个图像,它应该重定向到另一个URL.
JQuery如下.
$(function () {
$('#link-table td:first-child').hide();
$('#link-table tr').hover(function () {
$(this).toggleClass('highlight');
});
$('#link-table tr').click(function () {
location.href = $(this).find('td a').attr('href');
});
});
Run Code Online (Sandbox Code Playgroud)
单击该行工作,单击最后一个单元格中的图像超链接重定向到与单击不是我想要的行相同的URL.
我尝试将此代码用于click事件
$('#link-table tr td:not(:last-child))').click(function () {
location.href = $(this).find('td a').attr('href');
});
Run Code Online (Sandbox Code Playgroud)
单击最后一个单元格中的图像超链接,但单击该行现在重定向到附加到最后一个单元格中的图像超链接的URL.
如何获取它,以便单击行重定向到一个URL,单击最后一个单元格中的超链接重定向到另一个?
Fre*_* LA 21
$('#link-table tr td:not(:last-child)').click(function () {
location.href = $(this).find('td a').attr('href');
});
Run Code Online (Sandbox Code Playgroud)
你$(this)是'#link-table tr td:not(:last-child))',你可以找到tr与
var tr = $(this).closest('tr');
这时你可以用var tr做任何你喜欢
然后找到'td a'等
| 归档时间: |
|
| 查看次数: |
10201 次 |
| 最近记录: |