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

directory search
速查表 核心 jQuery(selector jQuery(html jQuery(callback) each(callback) size() length selector context get([index]) index([selector|element]) data([key] removeData([name|list]) jQuery.data(element queue(element dequeue([queueName]) clearQueue([queueName]) jQuery.noConflict([extreme]) 選擇器 #id element .class * selector1 ancestor descendant parent > child prev + next prev ~ siblings :first :last :not(selector) :even :odd :eq(index) :gt(index) :lt(index) :header :animated :focus :contains(text) :empty :has(selector) :parent :hidden :visible [attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute$=value] [attribute*=value] [selector1][selector2][selectorN] :nth-child :first-child :last-child :only-child :input :text :password :radio :checkbox :submit :image :reset :button :file :hidden :enabled :disabled :checked :selected 屬性 attr(name|pro|key removeAttr(name) prop(name|pro|key removeProp(name) addClass(class|fn) removeClass([class|fn]) toggleClass(class|fn[ html([val|fn]) text([val|fn]) val([val|fn|arr]) 篩選 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 children([expr]) closest(expr find(expr|obj|ele) next([expr]) nextAll([expr]) nextUntil([exp|ele][ parent([expr]) parents([expr]) parentsUntil([exp|ele][ prev([expr]) prevAll([expr]) prevUntil([exp|ele][ siblings([expr]) add(expr|ele|html|obj[ andSelf() contents() end() 文檔處理 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[ CSS css(name|pro|[ offset([coordinates]) position() scrollTop([val]) scrollLeft([val]) height([val|fn]) width([val|fn]) innerHeight() innerWidth() outerHeight([options]) outerWidth([options]) 事件 ready(fn) on(events off(events bind(type one(type trigger(type triggerHandler(type unbind(type live(type die(type delegate(sel undelegate([sel hover([over toggle(fn blur([[data] change([[data] click([[data] dblclick([[data] error([[data] focus([[data] focusin([data] focusout([data] keydown([[data] keypress([[data] keyup([[data] mousedown([[data] mouseenter([[data] mouseleave([[data] mousemove([[data] mouseout([[data] mouseover([[data] mouseup([[data] resize([[data] scroll([[data] select([[data] submit([[data] unload([[data] 效果 show([speed hide([speed toggle([speed] slideDown([speed] slideUp([speed slideToggle([speed] fadeIn([speed] fadeOut([speed] fadeTo([[speed] fadeToggle([speed animate(param stop([cle] delay(duration jQuery.fx.off jQuery.fx.interval Ajax jQuery.ajax(url load(url jQuery.get(url jQuery.getJSON(url jQuery.getScript(url jQuery.post(url ajaxComplete(callback) ajaxError(callback) ajaxSend(callback) ajaxStart(callback) ajaxStop(callback) ajaxSuccess(callback) jQuery.ajaxSetup([options]) serialize() serializeArray() 工具 jQuery.support jQuery.browser jQuery.browser.version jQuery.boxModel jQuery.each(object jQuery.extend([deep] jQuery.grep(array jQuery.makeArray(obj) jQuery.map(array jQuery.inArray(val jQuery.toArray() jQuery.merge(first jQuery.unique(array) jQuery.parseJSON(json) jQuery.noop jQuery.proxy(function jQuery.contains(container jQuery.isArray(obj) jQuery.isFunction(obj) jQuery.isEmptyObject(obj) jQuery.isPlainObject(obj) jQuery.isWindow(obj) jQuery.isNumeric(value) jQuery.type(obj) jQuery.trim(str) jQuery.param(obj jQuery.error(message) Deferred def.done(donCal def.fail(failCal) def.isRejected() def.isResolved() def.reject(args) def.rejectWith(context def.resolve(args) def.resolveWith(context def.then(doneCal def.progress([type] def.pipe([donFil] def.always(alwCal def.notify(args) def.notifyWith(context def.progress(proCal) def.state() Callbacks callbacks.add(callbacks) callbacks.disable() callbacks.empty() callbacks.fire(arguments) callbacks.fired() callbacks.fireWith([context][ callbacks.has(callback) callbacks.lock() callbacks.locked() callbacks.remove(callbacks) jQuery.callbacks(flags) 關于 關于jQuery API 文檔 提交bug及獲取更新 其它 regexp
characters

返回值:jQuerylive(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" ,但是由于這個元素是在調用 .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. 如果找到了匹配的元素,那么調用原始的事件處理函數(shù)。
  7. 由于只有在事件發(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。 僅僅調用 .stopPropagation() 無法實現(xiàn)這個目的。

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

    在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.
    });

參數(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: