JQuery – 可点击表格行,最后一个单元格除外

我正在尝试使用 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');
    });
});

单击该行工作,单击上一个单元格中的图像超链接重定向到相同的URL,单击不是我想要的行.

我尝试使用这个代码进行点击事件

$('#link-table tr td:not(:last-child))').click(function () {
        location.href = $(this).find('td a').attr('href');
    });

单击上一个单元格中的图像超链接可以工作,但单击该行现在将重定向到最后一个单元格中连接到图像超链接的URL.

如何获取它,以便单击行重定向一个URL,单击上一个单元格中的超链接重定向到另一个

解决方法

$('#link-table tr td:not(:last-child)').click(function () {
        location.href = $(this).find('td a').attr('href');
    });

你的$(this)是’#link-table tr td:not(:last-child))’,你可以找到tr
var tr = $(this).closest(‘tr’);
那么你可以使用var tr来做任何你喜欢的事情

然后找到“td a”等

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...