jQuery API 返回首页目录 | jQuery API 中英文对照版
unbind(type, fn)
unbind(type,fn)

反绑定,从每一个匹配的元素中删除绑定的事件。

如果没有参数,则删除所有绑定的事件。 如果提供了事件类型作为参数,则只删除该类型的绑定事件。 如果把在绑定时传递的处理函数作为第二个参数,则只有这个特定的事件处理函数会被删除。

返回值:jQuery

参数:

  • type (String): (可选) 事件类型
  • fn (Function): (可选) 要从每个匹配元素的事件中反绑定的事件处理函数

示例:

$("p").unbind()

HTML 代码:

<p onclick="alert('Hello');">Hello</p>

结果:

[ <p>Hello</p> ]

示例:

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

HTML 代码:

<p onclick="alert('Hello');">Hello</p>

结果:

[ <p>Hello</p> ]

示例:

$("p").unbind( "click", function() { alert("Hello"); } )

HTML 代码:

<p onclick="alert('Hello');">Hello</p>

结果:

[ <p>Hello</p> ]

 
unbind(type,fn)

The opposite of bind, removes a bound event from each of the matched elements.

Without any arguments, all bound events are removed.

If the type is provided, all bound events of that type are removed.

If the function that was passed to bind is provided as the second argument, only that specific event handler is removed.

Return value: jQuery
Parameters:

  • type (String): (optional) An event type
  • fn (Function): (optional) A function to unbind from the event on each of the set of matched elements

Example:

 $("p").unbind()  
Before:
 <p onclick="alert('Hello');">Hello</p>  
Result:
 [ <p>Hello</p> ]  

Example:

 $("p").unbind( "click" )  
Before:
 <p onclick="alert('Hello');">Hello</p>  
Result:
 [ <p>Hello</p> ]  

Example:

 $("p").unbind( "click", function() { alert("Hello"); } )  
Before:
 <p onclick="alert('Hello');">Hello</p>  
Result:
 [ <p>Hello</p> ]  


相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog