亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
快速查詢 核心 jQuery([selector,[context]]) jQuery(html,[ownerDocument]) jQuery(callback) jQuery.holdReady(hold) jQuery.readyException( error ) each(callback) size() length selector context get([index]) index([selector|element]) data([key],[value]) removeData([name|list]) jQuery.data(element,[key],[value]) queue(element,[queueName]) dequeue([queueName]) clearQueue([queueName]) jQuery.fn.extend(object) jQuery.extend(object) jQuery.noConflict([extreme]) 選擇器 #id element .class * selector1,selector2,selectorN ancestor descendant parent > child prev + next prev ~ siblings :first :not(selector) :even :odd :eq(index) :gt(index) :lang(language) :last() :lt(index) :header :animated :focus :root :target :contains(text) :empty :has(selector) :parent :hidden :visible [attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute*=value] [selector1][selector2][selectorN] :first-child :first-of-type :last-child :last-of-type :nth-child :nth-last-child(n|even|odd|formula) :nth-last-of-type(n|even|odd|formula) :nth-of-type(n|even|odd|formula) :only-child :only-of-type :input :text :password :radio :checkbox :submit :image :reset :button :file :enabled :disabled :checked :selected $.escapeSelector(selector) AJAx $.ajax(url,[settings]) $.get(url,[data],[fn],[type]) $.getJSON(url,[data],[fn]) $.getScript(url,[callback]) $.post(url,[data],[fn],[type]) ajaxComplete(callback) ajaxError(callback) ajaxSend(callback) ajaxStart(callback) ajaxStop(callback) ajaxSuccess(callback) $.ajaxPrefilter([type],fn) $.ajaxSetup([options]) load(url, [data], [callback]) serialize() serializeArray() 屬性 attr(name|properties|key,value|fn) removeAttr(name) prop(n|p|k,v|f) removeProp(name) addClass(class|fn) removeClass([class|fn]) toggleClass(class|fn[,sw]) html([val|fn]) text([val|fn]) val([val|fn|arr]) CSS css(name|pro|[,val|fn]) jQuery.cssHooks offset([coordinates]) position() scrollTop([val]) scrollLeft([val]) height([val|fn]) width([val|fn]) innerHeight() innerWidth() outerHeight([options]) outerWidth([options]) 文檔處理 append(content|fn) appendTo(content) prepend(content|fn) prependTo(content) after(content|fn) before(content|fn) insertAfter(content) insertBefore(content) wrap(html|ele|fn) unwrap() wrapall(html|ele) wrapInner(html|ele|fn) replaceWith(content|fn) replaceAll(selector) empty() remove([expr]) detach([expr]) clone([Even[,deepEven]]) 篩選 eq(index|-index) first() last() hasClass(class) filter(expr|obj|ele|fn) is(expr|obj|ele|fn) map(callback) has(expr|ele) not(expr|ele|fn) slice(start,[end]) children([expr]) closest(e|o|e) find(e|o|e) next([expr]) nextAll([expr]) nextUntil([e|e][,f]) offsetParent() parent([expr]) parents([expr]) parentsUntil([e|e][,f]) prev([expr]) prevall([expr]) prevUntil([e|e][,f]) siblings([expr]) add(e|e|h|o[,c]) andSelf() addBack() contents() end() 事件 ready(fn) on(eve,[sel],[data],fn) off(eve,[sel],[fn]) bind(type,[data],fn) one(type,[data],fn) trigger(type,[data]) triggerHandler(type, [data]) unbind(t,[d|f]) live(type,[data],fn) die(type,[fn]) delegate(s,[t],[d],fn) undelegate([s,[t],fn]) hover([over,]out) toggle([s],[e],[fn]) blur([[data],fn]) change([[data],fn]) click([[data],fn]) dblclick([[data],fn]) error([[data],fn]) focus([[data],fn]) focusin([data],fn) focusout([data],fn) keydown([[data],fn]) keypress([[data],fn]) keyup([[data],fn]) mousedown([[data],fn]) mouseenter([[data],fn]) mouseleave([[data],fn]) mousemove([[data],fn]) mouseout([[data],fn]) mouseover([[data],fn]) mouseup([[data],fn]) resize([[data],fn]) scroll([[data],fn]) select([[data],fn]) submit([[data],fn]) unload([[data],fn]) 效果 show([s,[e],[fn]]) hide([s,[e],[fn]]) toggle([s],[e],[fn]) slideDown([s],[e],[fn]) slideUp([s,[e],[fn]]) slideToggle([s],[e],[fn]) fadeIn([s],[e],[fn]) fadeOut([s],[e],[fn]) fadeTo([[s],o,[e],[fn]]) fadeToggle([s,[e],[fn]]) animate(p,[s],[e],[fn]) stop([c],[j]) delay(d,[q]) finish([queue]) jQuery.fx.off jQuery.fx.interval 工具 $.support $.browser $.browser.version $.boxModel $.each(object,[callback]) $.extend([d],tgt,obj1,[objN]) $.grep(array,fn,[invert]) $.sub() $.when(deferreds) $.makearray(obj) $.map(arr|obj,callback) $.inArray(val,arr,[from]) $.toArray() $.merge(first,second) $.unique(array) $.uniqueSort(array) $.parseJSON(json) $.parseXML(data) $.noop $.proxy(function,context) $.contains(c,c) $.type(obj) $.isArray(obj) $.isFunction(obj) $.isEmptyObject(obj) $.isPlainObject(obj) $.isWindow(obj) $.isNumeric(value) $.trim(str) $.param(obj,[traditional]) $.error(message) $.fn.jquery 事件對象 eve.currentTarget eve.data eve.delegateTarget eve.isDefaultPrevented() eve.isImmediatePropag...() eve.isPropagationStopped() eve.namespace eve.pageX eve.pageY eve.preventDefault() eve.relatedTarget eve.result eve.stopImmediatePro...() eve.stopPropagation() eve.target eve.timeStamp eve.type eve.which 延遲對象 def.done(d,[d]) def.fail(failCallbacks) def.isRejected() def.isResolved() def.reject(args) def.rejectWith(c,[a]) def.resolve(args) def.resolveWith(c,[a]) def.then(d[,f][,p]) def.promise([ty],[ta]) def.pipe([d],[f],[p]) def.always(al,[al]) def.notify(args) def.notifyWith(c,[a]) def.progress(proCal) def.state() 回調(diào)函數(shù) cal.add(callbacks) cal.disable() cal.empty() cal.fire(arguments) cal.fired() cal.fireWith([c] [,a]) cal.has(callback) cal.lock() cal.locked() cal.remove(callbacks) $.callbacks(flags) 正則表達式
characters

返回值:jQuery

live(type, [data], fn)

概述

jQuery 給所有匹配的元素附加一個事件處理函數(shù),即使這個元素是以后再添加進來的也有效。

這個方法是基本是的 .bind() 方法的一個變體。使用 .bind() 時,選擇器匹配的元素會附加一個事件處理函數(shù),而以后再添加的元素則不會有。為此需要再使用一次 .bind() 才行。比如說

<body>
  <div class="clickme">Click here</div>
</body>

可以給這個元素綁定一個簡單的click事件:

$('.clickme').bind('click', function() {
  alert("Bound handler called.");
});

當點擊了元素,就會彈出一個警告框。然后,想象一下這之后有另一個元素添加進來了。

$('body').append('<div class="clickme">Another target</div>');

盡管這個新的元素也能夠匹配選擇器 ".clickme" ,但是由于這個元素是在調(diào)用 .bind() 之后添加的,所以點擊這個元素不會有任何效果。

.live() 就提供了對應這種情況的方法。如果我們是這樣綁定click事件的:

$('.clickme').live('click', function() {
  alert("Live handler called."); 
});

然后再添加一個新元素:

$('body').append('<div class="clickme">Another target</div>');

然后再點擊新增的元素,他依然能夠觸發(fā)事件處理函數(shù)。

事件委托

.live() 方法能對一個還沒有添加進DOM的元素有效,是由于使用了事件委托:綁定在祖先元素上的事件處理函數(shù)可以對在后代上觸發(fā)的事件作出回應。傳遞給 .live() 的事件處理函數(shù)不會綁定在元素上,而是把他作為一個特殊的事件處理函數(shù),綁定在 DOM 樹的根節(jié)點上。在我們的例子中,當點擊新的元素后,會依次發(fā)生下列步驟:

  1. 生成一個click事件傳遞給                        來處理

  2. 由于沒有事件處理函數(shù)直接綁定在 <divgt; 上,所以事件冒泡到DOM樹上

  3. 事件不斷冒泡一直到DOM樹的根節(jié)點,默認情況下上面綁定了這個特殊的事件處理函數(shù)。

  4. 執(zhí)行由 .live() 綁定的特殊的 click 事件處理函數(shù)。

  5. 這個事件處理函數(shù)首先檢測事件對象的 target 來確定是不是需要繼續(xù)。這個測試是通過檢測 $(event.target).closest('.clickme') 能否找到匹配的元素來實現(xiàn)的。

  6. 如果找到了匹配的元素,那么調(diào)用原始的事件處理函數(shù)。

由于只有在事件發(fā)生時才會在上面的第五步里做測試,因此在任何時候添加的元素都能夠響應這個事件。

附加說明

.live() 雖然很有用,但由于其特殊的實現(xiàn)方式,所以不能簡單的在任何情況下替換 .bind()。主要的不同有:

  • 在jQuery 1.4中,.live()方法支持自定義事件,也支持所有的 JavaScript 事件。在jQuery 1.4.1中,甚至也支持 focus 和 blue 事件了(映射到更合適,并且可以冒泡的focusin和focusout上)。另外,在jQuery 1.4.1中,也能支持hover(映射到"mouseenter mouseleave")。然而在jQuery 1.3.x中,只支持支持的JavaScript事件和自定義事件:click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, 和 mouseup.

  • .live() 并不完全支持通過DOM遍歷的方法找到的元素。取而代之的是,應當總是在一個選擇器后面直接使用 .live() 方法,正如前面例子里提到的。

  • 當一個事件處理函數(shù)用 .live() 綁定后,要停止執(zhí)行其他的事件處理函數(shù),那么這個函數(shù)必須返回 false。 僅僅調(diào)用 .stopPropagation() 無法實現(xiàn)這個目的。

參考 .bind() 方法可以獲得更多關(guān)于事件綁定的信息。

在jQuery 1.4.1 中,.live() 能接受多個,用空間分隔事件,在提供類似.bind()的功能 。例如,我們可以“l(fā)ive ” 同時綁定mouseover和mouseout事件,像這樣:

$('.hoverme').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {
    // do something on mouseover
  } else {
    // do something on mouseout
  }
});

在jQuery 1.4.3中:你可以綁定一個或多個事件類型的字符串和函數(shù)的數(shù)據(jù)映射來執(zhí)行他們

$("a").live({
  click: function() {
    // do something on click
  },
  mouseover: function() {
    // do something on mouseover
  }
});

在jQuery 1.4 中,data參數(shù)可以用于把附加信息傳遞給事件處理函數(shù)。一個很好的用處是應付由閉包導致的問題??梢詤⒖?.bind() 的討論來獲得更多信息。

在jQuery 1.4 中, live事件可以綁定到“context”DOM元素,而不是默認的文檔的根。要設置此背景下,我們通過在一個單一的DOM元素(而不是一個jQuery集合或選擇器)使用jQuery() function's second argument。

$('div.clickme', $('#container')[0]).live('click', function() {
  // Live handler called.
});

從 jQuery 1.7 開始,不再建議使用 .live() 方法。請使用 .on() 來添加事件處理。使用舊版本的用戶,應該優(yōu)先使用 .delegate() 來替代 .live()。

參數(shù)

type,[fn]String,FunctionV1.3

type:一個或多個事件類型,由空格分隔多個事件。

fn:要從每個匹配元素的事件中反綁定的事件處理函數(shù)

type,[data],falseString,Array,boolV1.4

type:一個或多個事件類型,由空格分隔多個事件。

data:傳遞給事件處理函數(shù)的附加參數(shù)

false:設置為false會使默認的動作失效。

eventStringV1.4.3

一個或多個事件類型的字符串和函數(shù)的數(shù)據(jù)映射來執(zhí)行他們

示例

描述:

點擊生成的p依然據(jù)有同樣的功能。

HTML 代碼:
<p>Click me!</p>
jQuery 代碼:
$("p").live("click", function(){
    $(this).after("<p>Another paragraph!</p>");
});

描述:

阻止默認事件行為和事件冒泡,返回 false

jQuery 代碼:
$("a").live("click", function() { return false; });

描述:

僅僅阻止默認事件行為

jQuery 代碼:
$("a").live("click", function(event){
  event.preventDefault();
});


Previous article: Next article: