一:
$.fn.simpleTree = function(opt){
}
simpleTree 算是一個function類型的屬性。是jQuery類實例對象的一個函數,
$("#id").
simpleTree ()就可以調用
$.fn 是$這個對象的原型引用
simpleTree 就是在$原型里面添加的一個
simpleTree 的方法。
二:
實現樹時,會通過這種方式。
$(document).ready(function(){
simpleTreeCollection = $('.simpleTree').simpleTree(
{
autoclose: true,
animate:true
});
});
然后,我們就需要問了
autoclose 和 animate 這二個屬性是如果賦值的。
查看源碼發展如下:
TREE.option = {
drag: true,
animate: false,
autoclose: false,
speed: 'fast',
afterAjax: false,
afterMove: false,
afterClick: false,
afterDblClick: false,
// added by Erik Dohmen (2BinBusiness.nl) to make context menu cliks available
afterContextMenu: false,
docToFolderConvert:false
};
難道我們能過 Tree.option 創建的數組,可以在方法中直接賦值嗎?
千萬別去追查 option 是什么特殊字符,這樣會跟我犯同一個錯誤, option 就是一個簡單的變量名而已。
真正的賦值是下面這個方法:
TREE.option = $.extend(TREE.option,opt);
jquery 文檔這樣解釋: 用一個或多個其他對象來擴展一個對象,返回這個被擴展的對象
參考資料: http://www.tkk7.com/gen-sky/articles/310411.html
三: