js 回調函數
function startMove(obj,json,fnEnd){ // 鏈接的不能用this this--》window /* if(fn) { fn(); } */ // 鏈接的能用this if(fn) { fn.call(obj);} }
擴展jQuery對象本身
jQuery.extend({ min: function(a, b) { return a < b ? a : b; }, max: function(a, b) { return a > b ? a : b; } }); jQuery.min(2,3); // => 2 jQuery.max(4,5); // => 5
擴展 jQuery 元素集來提供新的方法(通常用來製作插件)
jQuery.fn.extend({ check: function() { return this.each(function() { this.checked = true; }); }, uncheck: function() { return this.each(function() { this.checked = false; }); } }); $("input[type=checkbox]").check(); $("input[type=radio]").uncheck();