一、类型判断函数
var obj = { name : "car" };
$. type(obj);//j Query 对象类型判断函数
console.log($. type(obj));// 返回 object
console.log($. type(null));// 返回 null
console.log($. type([]));// 返回 array
$. isEmptyObject("" );// 检查一个对象是否包含属性,不包含返回 true
console.log($. isEmptyObject("" ));// 返回 true
console.log($. isEmptyObject({}));// 返回 true
console.log($. isEmptyObject(obj));// 返回 false
$. isPlainObject(obj);// 检查一个对象是否包含属性,只有当该对象为 Object 类型并且包含属性时返回 true
$. isFunction(obj);// false 检查对象是否为一个函数
二、数组处理函数
var objArray = $.markArray(obj);
console.log($.isArray(objArray));
console.log(objArray);
var nums = [1 ,2 ,3 ,1 ];
var names = ["Peter" ,"Jim" ];
console.log($.merge(nums,names));
console.log($.unique(nums));
console.log($.inArray(1 ,nums));
$.each(nums,function (index,value) {
value = value * 2 ;
console.log("索引 " +index+" 的新值为:" + value);
});
console.log(nums);
var newArray = $.map(nums,function (value,index) ){
return value*2 +7 ;
}
console.log(newArray);
$.grep(newArray,function (n,index) {
return n > 2 ;
});
console.log($.inArray(18 ,nums));
console.log($("p" ));
$.when($.ajax("test.php" )).then(function () {
console.log("执行完 when 执行 then" );
});
三、网络异步请求相关函数
var ajaxApp = {
log:function (fn) { console.log("global Ajax " + fn.name);};
complete:this.log("complete" ),
error:this.log("error" ),
send:this.log("send" ),
start:this.log("start" ),
stop:this.log("stop" ),
success:this.log("success" )
}
$.ajaxSetup(options)
$.ajaxComplete(ajaxApp.complete);
$.ajaxError(ajaxApp.error);
$.ajaxSend(ajaxApp.send);
$.ajaxStart(ajaxApp.start);
$.ajaxStop(ajaxApp.stop);
$.ajaxSuccess(ajaxApp.success);
$.ajax({
type:"GET" ,
dataType:"json" ,
error:universalGoofupFunction
});
四、数据处理相关函数
console.log ($. parseJSON("{}" ));
consoel.log ($. parseXML("<xml></xml>" ));
console.log ($. isXMLDoc());
console.log ($( "form" ).serialize());
console.log ($( "form" ).serializeArray());
五、DOM 相关工具函数
$.contains($("head" )[0 ],$("title" )[0 ]);
六、其他工具函数和属性
$. fx.off = true;
$. fx.interval = 100 ;
console.log ($. fx.off);
console.log ($. fx.interval);
console.log ($. now());
console.log ($. isWindow(window ));
console.log ($. support);
var person = {name:"Peter" };
console.log ($. extend(person,{"name" :"Tom" },{"age" :18 }));
console.log ($. noop);
console.log ($. trim (" 我是中国人 " ));
console.log ($. param({"name" :"Tom" ,"age" :19 }));
jQuery.error ("message" );
$. globalEval("var x=0;" );
console.log ($. fn.jquery);
七、$.Callbacks() 委托链
var foo = function (val) {
console.log("foo:" +val);
}
var bar = function (val) {
console.log("bar:" +val);
}
var callbacks = $.Callbacks();
callbacks.add(foo);
callbacks.fire("Hello" );
callbacks.add(bar);
callbacks.fire("world!" );
callbacks.fireWith(window, ['function' ,'action' ]);
callbacks.disable();
console.log(callbacks.disabled());
callbacks.fire("world2" );
callbacks.empty();
console.log(callbacks.fired());
console.log(callbacks.has(foo));
callbacks.lock();
console.log(callbacks.lock());
callbacks.disable(false );
console.log("disabled ?:" +callbacks.disabled());
callbacks.add(foo);
callbacks.add(bar);
callbacks.add(foo);
console.log(callbacks);
callbacks.remove(foo,bar);
var flags = "once memory unique stopOnFlse" ;
callbacks = $.Callbacks(flags);