21 一月 2010 @ 5:10 下午 

Javascript 在指定物件為變數時是傳「reference」,若不知道這個特性很容易搞不清楚你的值為啥被改掉了,jQuery的extend函式可以做deep Clone,也就是遞迴將物件裡頭的任一成員都做clone,但針對array好像有點問題,因此我寫了一支小function來呼叫,以後要做cloneObject時可以直接服用。

/*
 * cloneObject 會完整clone一個全新的Object
 * 若傳入的object是array, 則會回傳array
 */
(function($) {
	$.extend($, {
		cloneObject : function(obj){
			var newObj;
			if($.isArray(obj)){
				newObj = [];
				for(var i=0; i<obj.length; i++){
					newObj.push(arguments.callee(obj[i]));
				}
				return newObj;
			}else{
				newObj = {};
				return $.extend(true, newObj, obj);
			}
		}
	});
})(jQuery)

Posted By: BLACKBING
Last Edit: 21 一月 2010 @ 05:13 下午

EmailPermalinkComments (0)
Tags
Categories: jQuery, plugin
 07 六月 2009 @ 1:47 上午 
jQuery有個很方便的function:toggle,可以讓元素做指定的切換動作,若不指定任何參數,則可以讓元素做很簡單的隱藏、顯示的切換,很是方便。If they are shown, toggle makes them hidden (using the hide method). If they are hidden, toggle makes them shown (using the show method). 但今天突然發現在針對大量元素的隱藏顯示時,這個function效能很差。 More »
Posted By: BLACKBING
Last Edit: 19 六月 2009 @ 01:55 下午

EmailPermalinkComments (0)
Tags
 29 五月 2009 @ 12:09 上午 
  1. media(多媒體播放):http://www.malsup.com/jquery/media/
  2. GalleryView(擴充性極強的圖片瀏覽插件):http://spaceforaname.com/galleryview
  3. 取得youtube的影片縮圖:http://jquery-howto.blogspot.com/2009/05/jyoutube-jquery-youtube-thumbnail.html
  4. 讓AJAX動作能夠有歷始紀錄(history):http://www.asual.com/jquery/address/
  5. jstore可以用各種方式儲存client端資料:http://code.google.com/p/jquery-jstore/
Posted By: BLACKBING
Last Edit: 29 五月 2009 @ 12:11 上午

EmailPermalinkComments (0)
Tags
Categories: jQuery, plugin

 Last 50 Posts
Change Theme...
  • Users » 17
  • Posts/Pages » 59
  • Comments » 28
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About Me



    No Child Pages.

留言板



    No Child Pages.

Album



    No Child Pages.