开发者

JQuery unbinding a specific handler

开发者 https://www.devze.com 2023-01-25 08:43 出处:网络
Given the code below, how can you get unbind(\'click\', h) to work? It doesn\'t currently work.I could make h a global variable but I don\'t know how to \"set this up\" given the msg variable is set

Given the code below, how can you get unbind('click', h) to work?

It doesn't currently work. I could make h a global variable but I don't know how to "set this up" given the msg variable is set within the function.

??

function x(open) {
    var msg = "blah";

    var h = function (e) {
        e.preventDefault();
        showDialog(msg);
  开发者_Go百科  };

    if (open === true) {
        but.unbind('click');
        link.unbind('click');
    } else {
        but.click(h);
        link.click(h);
    }    
}


msg = "blah"

h = function(e) 
{ 
    e.preventDefault();
    showDialog(msg);
};

function x(open) 
{
    msg = "whatever";

    if (open === true) 
    {
        but.unbind('click', h);
        link.unbind('click', h);
    } 
    else 
    {
        but.click(h);       
        link.click(h);      
    }
}

*I Think

0

精彩评论

暂无评论...
验证码 换一张
取 消