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

directory search
jQuery 1.4.4 速查表 核心 jQuery核心函數(shù) jQuery(expression jQuery(html jQuery(html jQuery(elements) jQuery() jQuery(callback) jQuery對象訪問 each(callback) size() length context get() get(index) index([subject]) selector 數(shù)據(jù)緩存 data([name]) data(name data(obj) removeData(name) jQuery.data(element jQuery.data([element] 隊列機(jī)制 queue(name) queue(name queue(name dequeue(name) clearQueue([queueName]) 插件機(jī)制 jQuery.extend(object) jQuery.fn.extend(object) 多庫共存 jQuery.noConflict() jQuery.noConflict(extreme) 選擇器 基本 #id element .class * selector1 層級 ancestor descendant parent > child prev + next prev ~ siblings 基本(過濾器) :first :last :not :even :odd :eq :gt :lt :header :animated 內(nèi)容(過濾器) :contains :empty :has :parent 可見性(過濾器) :hidden :visible 屬性 [attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute$=value] [attribute*=value] [selector1][selector2][selectorN] 子元素 :first-child :last-child :nth-child :only-child 表單 :input :text :password :radio :checkbox :reset :submit :image :button :file :hidden 表單對象屬性 :checked :disabled :enabled :selected 屬性 屬性 attr(name) attr(properties) attr(key attr(key removeAttr(name) CSS類 addClass(class) addClass(function(index removeClass([class]) removeClass(function(index toggleClass(class) toggleClass(class toggleClass(function(index HTML代碼 html() html(val) html(function(index 文本 text() text(val) text(function(index val() val(val) val(array) val(function(index 篩選 過濾 eq(index) first() last() hasClass(class) filter(expr) filter(fn) is(expr) map(callback) has(expr) not(expr) slice(start 查找 children([expr]) closest(expr find(expr) next([expr]) nextAll([expr]) nextUntil([expr]) offsetParent() parent([expr]) parents([expr]) parentsUntil([expr]) prev([expr]) prevAll([expr]) prevUntil([expr]) siblings([expr]) 串聯(lián) add(expr andSelf() contents() end() 文檔處理 內(nèi)部插入 append(content) append(function(index appendTo(content) prepend(content) prepend(function(index prependTo(content) 外部插入 after(content) after(function) before(content) before(function) insertAfter(content) insertBefore(content) 包裹 wrap(html) wrap(elem) wrap(fn) unwrap() wrapAll(html) wrapAll(elem) wrapInner(html) wrapInner(elem) wrapInner(fn) 替換 replaceWith(content) replaceAll(selector) 刪除 empty() remove([expr]) detach([expr]) 復(fù)制 clone() clone(true) CSS CSS css(name) css(properties) css(name css(name 位置 offset() offset(coordinates) position() scrollLeft() scrollLeft(val) scrollTop() scrollTop(val) 尺寸 height() height(val) width() width(val) innerHeight() innerWidth() outerHeight(options) outerWidth(options) 事件 頁面載入 ready(fn) 事件處理 bind(type one(type trigger(type triggerHandler(type unbind([type] 事件委派 live(type die([type] delegate(selector undelegate() 事件切換 hover(over toggle(fn 事件 blur() blur(fn) change() change(fn) click() click(fn) dblclick() dblclick(fn) error() error(fn) focus() focus(fn) focusin(fn) focusout(fn) keydown() keydown(fn) keypress() keypress(fn) keyup() keyup(fn) load(fn) mousedown(fn) mousemove(fn) mouseout(fn) mouseover(fn) mouseup(fn) resize(fn) scroll(fn) select() select(fn) submit() submit(fn) unload(fn) 效果 基本 show() show(speed hide() hide(speed toggle() toggle(switch) toggle(speed 滑動 slideDown(speed slideUp(speed slideToggle(speed 淡入淡出 fadeIn(speed fadeOut(speed fadeTo(speed fadeToggle(speed 自定義 animate(params animate(params stop([clearQueue] delay(duration 設(shè)置 jQuery.fx.off jQuery.fx.interval AJAX AJAX請求 jQuery.ajax([options]) load(url jQuery.get(url jQuery.getJSON(url jQuery.getScript(url jQuery.post(url AJAX事件 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 數(shù)組和對象操作 jQuery.each(object jQuery.extend([deep] jQuery.grep(array jQuery.inArray(value jQuery.makeArray(obj) jQuery.toArray() jQuery.map(array jQuery.merge(first jQuery.unique(array) jQuery.parseJSON(json) 函數(shù)操作 jQuery.noop jQuery.proxy(function 測試操作 jQuery.contains(container jQuery.isArray(obj) jQuery.isFunction(obj) jQuery.isEmptyObject(obj) jQuery.isPlainObject(obj) jQuery.isWindow(obj) jQuery.type(obj) 字符串操作 jQuery.trim(str) URL解析 jQuery.param(obj 插件編寫 jQuery.error(message) 關(guān)于 關(guān)于jQuery API 1.4.4中文版 關(guān)于jQuery 1.4.1中文版 關(guān)于jQuery 1.3 版翻譯 關(guān)于jQuery 1.2 版翻譯 提交bug及獲取更新
characters

返回值:jQuerybind(type, [data], fn)

概述

為每個匹配元素的特定事件綁定事件處理函數(shù)。

.bind() 方法是用于往文檔上附加行為的主要方式。所有JavaScript事件對象,比如focus, mouseover, 和 resize,都是可以作為type參數(shù)傳遞進(jìn)來的。
		
jQuery還提供了一些綁定這些標(biāo)準(zhǔn)事件類型的簡單方式,比如.click()用于簡化.bind('click')。一共有以下這些:blur, focus, focusin, focusout, load, resize, scroll, unload, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, keyup, error 。

任何作為type參數(shù)的字符串都是合法的;如果一個字符串不是原生的JavaScript事件名,那么這個事件處理函數(shù)會綁定到一個自定義事件上。這些自定義事件絕對不會由瀏覽器觸發(fā),但可以通過使用.trigger()或者.triggerHandler()在其他代碼中手動觸發(fā)。

如果type參數(shù)的字符串中包含一個點(.)字符,那么這個事件就看做是有命名空間的了。這個點字符就用來分隔事件和他的命名空間。舉例來說,如果執(zhí)行 .bind('click.name', handler) ,那么字符串中的 click 是事件類型,而字符串 name 就是命名空間。命名空間允許我們?nèi)∠壎ɑ蛘哂|發(fā)一些特定類型的事件,而不用觸發(fā)別的事件。參考unbind()來獲取更多信息。

當(dāng)一個事件傳到一個元素上,所有綁定在上面的針對哪個事件的處理函數(shù)都會觸發(fā)。如果注冊了多個事件處理函數(shù),總是按照綁定的順序依次觸發(fā)。當(dāng)所有綁定的事件處理函數(shù)執(zhí)行完畢后,事件繼續(xù)沿著普通的事件冒泡途徑上浮。

.bind()最基本的用法是:

<pre>
$('#foo').bind('click', function() {
  alert('User clicked on "foo."');
});
</pre>

這個代碼能使ID為foo的元素響應(yīng)click事件。當(dāng)用戶點擊元素內(nèi)部之后,就會彈出一個警告框。

'''多個事件'''

依次可以綁定多個事件類型,每個事件類型用空格分隔:

<pre>
$('#foo').bind('mouseenter mouseleave', function() {
  $(this).toggleClass('entered');
});
</pre>

這個代碼讓一個&lt;div id="foo"&gt;元素(初始情況下class沒有設(shè)置成entered),當(dāng)鼠標(biāo)移進(jìn)去的時候,在class中加上entered,而當(dāng)鼠標(biāo)移出這個div的時候,則去除這個class值。

在jQuery 1.4中,我們也可以通過傳入一個映射對來一次綁定多個事件處理函數(shù):

<pre>
$('#foo').bind({
  click: function() {
    // do something on click
  },
  mouseenter: function() {
    // do something on mouseenter
  }
});
</pre>

'''事件處理函數(shù)'''

fn這個參數(shù)接受一個回調(diào)函數(shù),就像先前展示的那樣。在這個事件處理函數(shù)內(nèi)部,this指向這個函數(shù)綁定的DOM元素。如果要讓這個元素變成jQuery對象來使用jQuery的方法,可以把這個對象傳入 $() 重新封裝。比如說:

<pre>$('#foo').bind('click', function() {
  alert($(this).text());
});
</pre>

這個代碼執(zhí)行之后,當(dāng)用戶點擊了ID為foo的元素內(nèi)部之后,他的文本內(nèi)容就會出現(xiàn)在一個警告框中。

'''事件對象'''

fn這個參數(shù)的回調(diào)函數(shù)還可以接受一個參數(shù)。當(dāng)這個函數(shù)被調(diào)用時,一個JavaScript事件對象會作為一個參數(shù)傳進(jìn)來。

這個事件對象通常是沒有必要且可以省略的參數(shù),因為當(dāng)這個事件處理函數(shù)綁定的時候就能夠明確知道他在觸發(fā)的時候應(yīng)該做些什么,通常就已經(jīng)可以獲得充分的信息了。然而在有些時候,在事件初始化的時候需要獲取更多關(guān)于用戶環(huán)境的信息??梢詤⒖纪暾年P(guān)于<a href="/category/events/event-object/">事件對象</a>的內(nèi)容(英文)。

在事件處理函數(shù)內(nèi)返回false就等價于執(zhí)行事件對象上的.preventDefault()和.stopPropagation()。

可以像這樣在事件處理函數(shù)內(nèi)使用事件對象:

<pre>$(document).ready(function() {
  $('#foo').bind('click', function(event) {
    alert('The mouse cursor is at ('
      + event.pageX + ', ' + event.pageY + ')');
  });
});
</pre>

注意,這個參數(shù)添加到了一個匿名函數(shù)上。這個代碼可以讓用戶在點擊ID為foo的元素時,報告鼠標(biāo)點擊時相對于頁面的坐標(biāo)。

'''傳遞事件數(shù)據(jù)'''

可選的第二個參數(shù)data通常用的很少。如果提供了這個參數(shù),那么我們就能把一些附加信息傳遞給事件處理函數(shù)了。這個參數(shù)有個很好的用處,就是處理閉包帶來的問題。比如我們有兩個事件處理函數(shù)要指向同一個內(nèi)部變量:

<pre>var message = 'Spoon!';
$('#foo').bind('click', function() {
  alert(message);
});
message = 'Not in the face!';
$('#bar').bind('click', function() {
  alert(message);
});
</pre>

由于這兩個函數(shù)在他們各自的環(huán)境中都有message,所以觸發(fā)時顯示的消息都是 Not in the face! 。變量值被改變了。為了回避這個問題,我們可以把message變量作為data參數(shù)傳遞進(jìn)去:

<pre>var message = 'Spoon!';
$('#foo').bind('click', {msg: message}, function(event) {
  alert(event.data.msg);
});
message = 'Not in the face!';
$('#bar').bind('click', {msg: message}, function(event) {
  alert(event.data.msg);
});
</pre>

這時在函數(shù)內(nèi)部不再直接指向這個變量了;取而代之的是按值傳遞給了data參數(shù),他能保持綁定事件時的值。第一個函數(shù)現(xiàn)在會顯示Spoon!,而第二個則顯示Not in the face!

注意,如果這個對象按引用傳遞給了函數(shù),那么將會使情況變得極其復(fù)雜。

另外,可以參考.trigger()方法來了解如何在事件觸發(fā)時傳遞數(shù)據(jù),而不是在事件綁定的時候傳遞數(shù)據(jù)。

在jQuery 1.4中,不再支持把數(shù)據(jù)以及事件附加到一個object、embed或者applet元素上面。因為當(dāng)往Java applet元素上附加數(shù)據(jù)時,會觸發(fā)一個嚴(yán)重錯誤警告。
		

用法 V1.4.3新增

bind(Type, [Data], false)

將第三個參數(shù)設(shè)置為false會使默認(rèn)的動作失效。

參數(shù)

typeString

含有一個或多個事件類型的字符串,比如"click"或"submit",還可以是自定義事件名。

data (可選)Object

作為event.data屬性值傳遞給事件對象的額外數(shù)據(jù)對象

fnFunction

綁定到每個匹配元素的事件上面的處理函數(shù)

示例

描述:

當(dāng)每個段落被點擊的時候,彈出其文本。

jQuery 代碼:
$("p").bind("click", function(){
  alert( $(this).text() );
});

描述:

你可以在事件處理之前傳遞一些附加的數(shù)據(jù)。

jQuery 代碼:
function handler(event) {
  alert(event.data.foo);
}
$("p").bind("click", {foo: "bar"}, handler)

描述:

通過返回false來取消默認(rèn)的行為并阻止事件起泡。

jQuery 代碼:
$("form").bind("submit", function() { return false; })

描述:

通過使用 preventDefault() 方法只取消默認(rèn)的行為。

jQuery 代碼:
$("form").bind("submit", function(event){
  event.preventDefault();
});

描述:

通過使用 stopPropagation() 方法只阻止一個事件起泡。

jQuery 代碼:
$("form").bind("submit", function(event){
  event.stopPropagation();
});
Previous article: Next article: