开发者

Jquery - Multi-Unbind

what is the best way to unbind all?

For example

i start a function someName('mp3Player')

in this function are many binds

function someName(mode)
{
  if(mode == 'exit')
  {
    $('#player').remove();
    // unbind all 
    // ..........
    return true;
  }  

  if(mode == 'mp3Player')
  {
     $('body').append('<div id="player"> *** add some html code *** </div>');
     $('#test').draggable ....
     $('.myLi').sortable ....
     $('myButton开发者_开发知识库').click ....
     $('.dragable').live( "dragstop", function (event, ui) ....
     return true;
  }

}

Any good ideas?

Thanks in advance!

Peter


you can use unbind or die

jquery unbind

jquery die

in your case you are live bundingthe event so its better/necessary to usedie` as

$('.dragable').die('dragstop');

to unbind single event as maxedison mentioned do

$("element").unbind("eventName");

this will unbind the event attached to the element to unbind all the events attached to an element call unbind without any arguments

$("selector").unbind();


The simplest way to do it would be to simply call something like the following on each element:

$('mySelector').unbind('eventName');

For example:

$('.myButton').unbind('click');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜