jQuery tips

jQuery就是簡化JavaScript語言代碼,提供一種簡單快速的接口。

1.selector

可以進行序列化操作,所有操作都是基於初始選擇的元素。選擇出來就是包裝集。

http://blog.csdn.net/luan_tianjiao/article/details/47130517

2.tools & attributes

$.trim(yourString)

http://blog.csdn.net/luan_tianjiao/article/details/47173063

http://blog.csdn.net/luan_tianjiao/article/details/47147793

3.event

http://write.blog.csdn.net/postedit

4.animation

http://blog.csdn.net/luan_tianjiao/article/details/47154581

5.plugin

http://blog.csdn.net/luan_tianjiao/article/details/47191777

6.document ready

動態操作文檔結構,前提是需要文檔完整加載完畢。如果使用window.onload判斷,它不僅是構建DOM樹之後,所有圖像和其他的外部資源加載完畢,並且在瀏覽器上顯示完畢之後。

jQuery提供了這樣的方法 $(document).ready(function(){  ur code here to manipulate the dom tree.  });

簡寫版本 $(function(){ ur code here to manipulate the dom tree.   });

7.custom function call

如果想要根據參數化調用動畫處理函數,可以使用下面方式

$('#testSubjects').children()[effect](speed,opacity);

effect可以是 "fadeTo" speed是"custom"等速度 opacity是飽和度 0.0-1.0

8.avoid nonsense query

下面的代碼可以爲jQuery擴展事件暫停和繼續方法
比如爲一個Dom對象 Button綁定click事件查詢數據,查詢期間不希望Button被點擊導致重複查詢
$(Button). pause();即可暫停事件處理 ,查詢完成後 $(Button).continue() 即可繼續事件處理
實現原理:jQuery綁定事件時會在目標Dom中緩存事件處理函數,並以每個頁面唯一的jQuery標識符 jQuery.expando命名,將$(Button).data(jQuery.expando)重命名,即可使事件失效,恢復命名即可恢復事件

$.fn.pause = function (callback) {
	try {
		this.data("pause" + $.expando, this.data($.expando));
		this.removeData($.expando);
		if (callback instanceof Function) callback.call(this);
	}
	catch (e) {
	}
}
$.fn.continue=function(callback){
	try {
		this.data($.expando, this.data("pause" + $.expando));
		this.removeData("pause" + $.expando);
		if (callback instanceof Function) callback.call(this);
	}
	catch (e) {
	}
} 




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章