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

目錄 搜尋
快速查詢 核心 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 事件對(duì)象 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 延遲對(duì)象 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) 正則表達(dá)式
文字

返回值:jQuery

live(type, [data], fn)

概述

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

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

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

可以給這個(gè)元素綁定一個(gè)簡(jiǎn)單的click事件:

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

當(dāng)點(diǎn)擊了元素,就會(huì)彈出一個(gè)警告框。然后,想象一下這之后有另一個(gè)元素添加進(jìn)來(lái)了。

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

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

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

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

然后再添加一個(gè)新元素:

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

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

事件委托

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

  1. 生成一個(gè)click事件傳遞給                        來(lái)處理

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

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

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

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

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

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

附加說(shuō)明

.live() 雖然很有用,但由于其特殊的實(shí)現(xiàn)方式,所以不能簡(jiǎ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() 并不完全支持通過(guò)DOM遍歷的方法找到的元素。取而代之的是,應(yīng)當(dāng)總是在一個(gè)選擇器后面直接使用 .live() 方法,正如前面例子里提到的。

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

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

在jQuery 1.4.1 中,.live() 能接受多個(gè),用空間分隔事件,在提供類似.bind()的功能 。例如,我們可以“l(fā)ive ” 同時(shí)綁定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中:你可以綁定一個(gè)或多個(gè)事件類型的字符串和函數(shù)的數(shù)據(jù)映射來(lái)執(zhí)行他們

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

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

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

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

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

參數(shù)

type,[fn]String,FunctionV1.3

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

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

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

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

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

false:設(shè)置為false會(huì)使默認(rèn)的動(dòng)作失效。

eventStringV1.4.3

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

示例

描述:

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

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

描述:

阻止默認(rèn)事件行為和事件冒泡,返回 false

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

描述:

僅僅阻止默認(rèn)事件行為

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


上一篇: 下一篇: