代码之家  ›  专栏  ›  技术社区  ›  Xiong Chiamiov

在jQuery中检索click()处理程序以供以后使用

  •  1
  • Xiong Chiamiov  · 技术社区  · 16 年前

    我正在使用jQuery tablesorter plugin 要对表进行排序,将.click()处理程序分配给 <th> fix_table_colors(identifier) 函数,当我使用Firebug手动调用它时,它应该这样做。不过,我想在排序之后自动调用它。

    <th> s、 并分配一个新的处理程序,该处理程序只调用前一个处理程序,后跟 fix_table_colors() .

    ( This

    从公认的答案到 this question

    $(document).ready(function() {
        $("table.torrents").tablesorter({
            debug: true,
            headers: {
                1: { sorter: 'name' },
                2: { sorter: 'peers' },
                3: { sorter: 'filesize' },
                4: { sorter: 'filesize' },
                5: { sorter: 'filesize' },
                6: { sorter: 'ratio' }
            }
        });
    
        $('table.torrents thead th').each(function() {
            var th = $(this);
            var clickHandler = th.data('events').click[0];
            th.click(function() {
                clickHandler();
                fix_table_colors('table.torrents');
            });
        });
    });
    

    虽然这在概念上是正确的, clickHandler

    在Firebug中进行了进一步的挖掘,我发现click[3]似乎保留了我正在寻找的函数(并单击[10]我的新函数)。不过,在使用tablesorter.min.js时,在第2行出现了一个“e is undefined”错误。

    1 回复  |  直到 9 年前
        1
  •  4
  •   Jonathan    16 年前

    绑定到分拣机怎么样( http://tablesorter.com/docs/example-triggers.html )这样的事件?

    $(document).ready(function() {
        $("table.torrents").tablesorter({
            debug: true,
            headers: {
                1: { sorter: 'name' },
                2: { sorter: 'peers' },
                3: { sorter: 'filesize' },
                4: { sorter: 'filesize' },
                5: { sorter: 'filesize' },
                6: { sorter: 'ratio' }
            }
        });
    
        $("table.torrents").bind("sortEnd",function() {
            fix_table_colors('table.torrents');
        });
    });