当对象继续动态更改时,取消注册实时单击事件

时间:2011-12-07 10:13:01

标签: jquery

我有一个div,我动态添加不同的表。

我需要维护一个已整理的列。

我使用全局变量来存储列名。

由于表格发生了变化(也可以动态添加不同的结构化表格)

我注册了一个TH(桌面点击事件)。我需要传递JSON url。

我使用LIVE事件,因为稍后会附加表格。

我希望在添加新表时取消注册所有TH点击事件。

我使用UNBIND,但它不起作用。我的点击事件用不同的参数点击两次。

代码:

            $("#" + control.attr("id") + " tr th").unbind("click");

            $("#" + control.attr("id") + " tr th").live(
            "click" , function()
            {

              var table_head = $(this);

              var  new_sort_column = (table_head.text());

              opts.columnName = new_sort_column;

              ColumnName = new_sort_column;

              opts.IsAscending = GlobalIsAscending ;

              GlobalIsAscending = !GlobalIsAscending ;

              getPageSet(control, opts, 0);

            }
            );

//可能需要 (此代码是我的jquery插件的一部分,其中Opts是jquery选项)

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

.live()会接受.die()从select中取消绑定事件。 api.jquery.com/die

顺便说一下你不需要重复$('选择器在这里')部分只是使用它作为以下$('blabla')。die('click')。live();

所以你的代码应该是

$("#" + control.attr("id") + " tr th").die('click').live("click" , function(){
    var table_head = $(this);
    var  new_sort_column = (table_head.text());
    opts.columnName = new_sort_column;
    ColumnName = new_sort_column;
    opts.IsAscending = GlobalIsAscending ;
    GlobalIsAscending = !GlobalIsAscending ;
    getPageSet(control, opts, 0);
});