jQuery 通用工具

2018-07-25 14:18 更新
$.each() $.map()
遍歷列表, $.map() 可以作用于對(duì)象。
$.each([52, 97], function(index, value) { 
  alert(index + ': ' + value); 
});

$.map( [0,1,2], function(index, n){
  return n + 4;
});
//[4, 5, 6]

$.map( [0,1,2], function(n){
  return n > 0 ? n + 1 : null;
});
//[2, 3]

$.map( [0,1,2], function(n){
  return [ n, n + 1 ];
});
//[0, 1, 1, 2, 2, 3]

var dimensions = { width: 10, height: 15, length: 20 };
$.map( dimensions, function( value, key ) {
  return value * 2;
});
//[20, 30, 40] 

var dimensions = { width: 10, height: 15, length: 20 },
$.map( dimensions, function( value, key ) {
  return key;
});
//["width", "height", "length"]
$.extend()
合并對(duì)象,第一個(gè)參數(shù)表示是否進(jìn)行遞歸深入
var object = $.extend({}, object1, object2);
var object = $.extend(true, {}, object1, object2);
$.merge()
合并列表
$.merge( [0,1,2], [2,3,4] )
//[0,1,2,2,3,4] 
$.grep()
過濾列表,第三個(gè)參數(shù)表示是否為取反
$.grep( [0,1,2], function(array,index){ return n > 0; }); //[1,2]
$.grep( [0,1,2], function(array,index){ return n > 0; }, true); //[0]
$.inArray()
存在判斷
$.inArray( value, array [, fromIndex] )
$.isArray() $.isEmptyObject() $.isFunction() $.isNumeric() $.isPlainObject()$.isWindow() $.isXMLDoc()
類型判斷
$.noop()
空函數(shù)
$.now()
當(dāng)前時(shí)間戳,值為 (new Date).getTime()
$.parseJson() $.parseXML()
把字符串解析為對(duì)象
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find( "title" );
$.trim()
去頭去尾, $.trim(str)
$.type()
判定參數(shù)的類型
# If the object is undefined or null,
#then "undefined" or "null" is returned accordingly.

* jQuery.type(undefined) === "undefined"
* jQuery.type() === "undefined"
* jQuery.type(window.notDefined) === "undefined"
* jQuery.type(null) === "null"

# If the object has an internal [[Class]] equivalent to
#one of the browser's built-in objects, the associated name is returned.
#(More details about this technique.)

* jQuery.type(true) === "boolean"
* jQuery.type(3) === "number"
* jQuery.type("test") === "string"
* jQuery.type(function(){}) === "function"
* jQuery.type([]) === "array"
* jQuery.type(new Date()) === "date"
* jQuery.type(/test/) === "regexp"
$.unique()
遍歷后去重, $.unique(array)


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)