toArray: function() { return slice.call( this, 0 ); }
2.当没有传递参数时get将返回一个数组,数组中包括所有元素。
$div.get(0); //等同于$("div:first"); $div.get().length === $("div").length; //true
3.jQuery提供的slice和eq方法都是支持负数参数的。
slice(begin[,end])是从0开始索引的,包括begin不包括end。没有传递第二个参数默认返回从第一个参数(包括第一个参数所在的元素)到最后一个元素。
index is 0 or -3
index is 1 or -2
index is 2 or -1
$("p").slice(-1);//last $("p").slice(1,2);//只返回index是1的p $("p").slice(1);//返回index 〉=1的所有p //可能看的还不够明了,直接上字符串好了 var str="string"; str.slice(1,2);//"t" str.slice(1);//"tring"
ruby也有slice方法,但是ruby的slice方法的两个参数的意义是不同的,第二个参数是截取字符串的长度。当没有给出第二个参数,默认是截取一个字符。
irb(main):001:0> "string".slice(1,2) => "tr" irb(main):002:0> "string".slice(1,2) => "t" irb(main):003:0>
4.isFunction
//if $.type == "function",isFounction() is true;others are false var function_demo = function(){ alert("I am function"); }; var not_function_demo = []; var $elem = $("div"); $.isFunction(function_demo);//true $.type(function_demo); //"function" $.isFunction(not_function_demo);//false $.type(not_function_demo); //"array" $.isFunction($elem);//false $.type($elem); //"object"
5.isArray
var arr_demo = []; $.type(arr_demo); //"array" $.isArray(arr_demo); //true
6.end()
(1)不接受任何参数
(2)end()将链的源头返回,达到find( ".bar" )是在$( "ul.first" )中查找
- list item 1
- list item 3
- list item 4
- list item 5