js回調、jquery 插件擴展

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();

 

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