最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

.unbind()

.unbind( eventType, handler(eventObject) ) Returns: jQuery

Description: Remove a previously-attached event handler from the elements.

  • version added: 1.0.unbind( eventType, handler(eventObject) )

    eventTypeA string containing a JavaScript event type, such as click or submit.

    handler(eventObject)The function that is to be no longer executed.

  • version added: 1.4.3.unbind( eventType, false )

    eventTypeA string containing a JavaScript event type, such as click or submit.

    falseUnbinds the corresponding 'return false' function that was bound using .bind( eventName, false ).

  • version added: 1.0.unbind( event )

    eventA JavaScript event object as passed to an event handler.

Any handler that has been attached with .bind() can be removed with .unbind(). In the simplest case, with no arguments, .unbind() removes all handlers attached to the elements:

$('#foo').unbind();

This version removes the handlers regardless of type. To be more precise, we can pass an event type:

$('#foo').unbind('click');

By specifying the click event type, only handlers for that event type will be unbound. This approach can still have negative ramifications if other scripts might be attaching behaviors to the same element, however. Robust and extensible applications typically demand the two-argument version for this reason:

var handler = function() {
  alert('The quick brown fox jumps over the lazy dog.');
};
$('#foo').bind('click', handler);
$('#foo').unbind('click', handler);

By naming the handler, we can be assured that no other functions are caught in the crossfire. Note that the following will not work:

$('#foo').bind('click', function() {
  alert('The quick brown fox jumps over the lazy dog.');
});

$('#foo').unbind('click', function() {
  alert('The quick brown fox jumps over the lazy dog.');
});

Even though the two functions are identical in content, they are created separately and so JavaScript is free to keep them as distinct function objects. To unbind a particular handler, we need a reference to that function and not a different one that happens to do the same thing.

Using Namespaces

Instead of maintaining references to handlers in order to unbind them, we can namespace the events and use this capability to narrow the scope of our unbinding actions. As shown in the discussion for the .bind() method, namespaces are defined by using a period (.) character when binding a handler:

$('#foo').bind('click.myEvents', handler);

When a handler is bound in this fashion, we can still unbind it the normal way:

$('#foo').unbind('click');

However, if we want to avoid affecting other handlers, we can be more specific:

$('#foo').unbind('click.myEvents');

If multiple namespaced handlers are bound, we can unbind them at once:

$('#foo').unbind('click.myEvents.yourEvents');

This syntax is similar to that used for CSS class selectors; they are not hierarchical. This method call is thus the same as:

$('#foo').unbind('click.yourEvents.myEvents');

We can also unbind all of the handlers in a namespace, regardless of event type:

$('#foo').unbind('.myEvents');

It is particularly useful to attach namespaces to event bindings when we are developing plug-ins or otherwise writing code that may interact with other event-handling code in the future.

Using the Event Object

The second form of the .unbind() method is used when we wish to unbind a handler from within itself. For example, suppose we wish to trigger an event handler only three times:

var timesClicked = 0;
$('#foo').bind('click', function(event) {
  alert('The quick brown fox jumps over the lazy dog.');
  timesClicked++;
  if (timesClicked >= 3) {
    $(this).unbind(event);
  }
});

The handler in this case must take a parameter, so that we can capture the event object and use it to unbind the handler after the third click. The event object contains the context necessary for .unbind() to know which handler to remove. This example is also an illustration of a closure. Since the handler refers to the timesClicked variable, which is defined outside the function, incrementing the variable has an effect even between invocations of the handler.

Examples:

Example: Can bind and unbind events to the colored button.

<!DOCTYPE html>
<html>
<head>
  <style>
button { margin:5px; }
button#theone { color:red; background:yellow; }
</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <button id="theone">Does nothing...</button>
<button id="bind">Bind Click</button>
<button id="unbind">Unbind Click</button>

<div style="display:none;">Click!</div>
<script>

function aClick() {
$("div").show().fadeOut("slow");
}
$("#bind").click(function () {
// could use .bind('click', aClick) instead but for variety...
$("#theone").click(aClick)
  .text("Can Click!");
});
$("#unbind").click(function () {
$("#theone").unbind('click', aClick)
  .text("Does nothing...");
});

</script>

</body>
</html>

Demo:

Example: To unbind all events from all paragraphs, write:

$("p").unbind()

Example: To unbind all click events from all paragraphs, write:

$("p").unbind( "click" )

Example: To unbind just one previously bound handler, pass the function in as the second argument:

var foo = function () {
// code to handle some kind of event
};

$("p").bind("click", foo); // ... now foo will be called when paragraphs are clicked ...

$("p").unbind("click", foo); // ... foo will no longer be called.
jQuery 1.6 API 中文版腳本之家整理、修訂 (2011年6月)
克拉玛依市| 太白县| 定边县| 河池市| 濮阳市| 阿合奇县| 益阳市| 辽宁省| 炎陵县| 鄂伦春自治旗| 文安县| 班戈县| 安宁市| 中卫市| 高碑店市| 大安市| 育儿| 婺源县| 定襄县| 昌平区| 邢台市| 界首市| 辛集市| 吉隆县| 陕西省| 彭泽县| 镇安县| 潢川县| 连州市| 金寨县| 曲麻莱县| 晋江市| 涪陵区| 伊金霍洛旗| 乌苏市| 酒泉市| 嘉鱼县| 仁化县| 肇庆市| 柯坪县| 徐水县|