jQuery设计理念
ajax链式操作
var jqxhr = $.ajax( "example.php" )
.done(function() { alert("success"); })
.fail(function() { alert("error"); })
.always(function() { alert("complete"); });
页面元素操作
$("p").removeClass("myClass noClass").addClass("yourClass");
$("ul li:last").addClass(function(index) {
return"item-" + index;
});
$('.container').append($('h2'));
jQuery整体架构
jQuery一共13个模块,
// 核心方法
// 回调系统
// 异步队列
// 数据缓存
// 队列操作
// 选择器引
// 属性操作
// 节点遍历
// 文档处理
// 样式操作
// 属性操作
// 事件体系
// AJAX交互
// 动画引擎
从2.1版开始jQuery支持通过AMD模块划分,jQuery在最开始发布的1.0版本是很简单的,只有CSS选择符、事件处理和AJAX交互3大块。其发展过程中,有几次重要的变革:
☑ 1.2.3 版发布,引入数据缓存,解决循环引用与大数据保存的问题
☑ 1.3 版发布,它使用了全新的选择符引擎Sizzle,在各个浏览器下全面超越其他同类型JavaScript框架的查询速度,程序库的性能也因此有了极大提升
☑ 1.5 版发布,新增延缓对像(Deferred Objects),并用deferred重写了Ajax模块
☑ 1.7 版发布,抽象出回调对象,提供了强大的的方式来管理回调函数列表。
jQuery文档针对业务层的Ajax的处理提供了一系列的门面接口:
.ajaxComplete()
.ajaxError()
.ajaxSend()
.ajaxStart()
.ajaxStop()
.ajaxSuccess()
底层接口:
jQuery.ajax()
jQuery.ajaxSetup()
快捷方法:
jQuery.get()
jQuery.getJSON()
jQuery.getScript()
jQuery.post()
// jQuery的写法
var $jQuery = function(selector, context) {
return new $jQuery.fn.init(selector, context);
}
$jQuery.fn = $jQuery.prototype = {
init: function() {
this.name = 'aaron'
return this;
},
constructor: $jQuery
}
var $a = $jQuery();
console.log('$jQuery的调用')
console.log($a);