标签:
1 <ul> 2 <li>0</li> 3 <li>1</li> 4 <li>2</li> 5 <li>3</li> 6 </ul> 7 <script src="jQuery.js"></script> 8 <script> 9 $(function(){ 10 var $Li = $(‘li‘); 11 console.log($Li.get(1)); //<li>1</li> index为非负数返回索引为index的DOM对象 12 console.log($Li.get(-1)); //<li>3</li> index为负数返回索引为index+length的DOM对象 13 console.log($Li.get()); //[1,2,3,4] index为空返回所有的DOM对象构成的类数组集合 14 }); 15 </script>
1 <div>div</div> 2 <span>span</span> 3 <script src="jQuery.js"></script> 4 <script> 5 $(function(){ 6 console.log($(‘div‘, ‘body‘)); // [0: ‘div‘, prevObject: $(‘body‘)] 7 console.log($(‘div‘).pushStack($(‘span‘))); // [0: ‘span‘, prevObject: $(‘div‘)] 8 }); 9 </script>
1 <div>div</div> 2 <span>span</span> 3 <script src="jQuery.js"></script> 4 <script> 5 $(function(){ 6 console.log($(‘div‘, ‘body‘)); // [0: ‘div‘, prevObject: $(‘body‘)] 7 console.log($(‘div‘).pushStack($(‘span‘)).end()); // [0: ‘div‘, prevObject: $(‘body‘)] 8 console.log($(‘div‘).pushStack($(‘span‘)).end() == $(‘div‘, ‘body‘)); //false 注意 9 console.log($(‘div‘).pushStack($(‘span‘)).end().end()); //[0: ‘document‘] 10 }); 11 </script>
1 <div>div0</div> 2 <div>div1</div> 3 <div>div2</div> 4 <div>div3</div> 5 <script src="jQuery.js"></script> 6 <script> 7 $(function(){ 8 var $Div = $(‘div‘); 9 console.log($Div.slice());// [0:div0,1:div1,2:div2,3:div3,prevObject:$(‘div‘)] 10 console.log($Div.slice(0,1));//[0:div0,prevObject:$(‘div‘)] 11 console.log($Div.slice(2));//[0:div2,1:div3,prevObject:$(‘div‘)] 12 console.log($Div.slice(-2,-1));//[0:div2,prevObject:$(‘div‘)] 13 console.log($Div.slice(-2));//[0:div2,1:div3,prevObject:$(‘div‘)] 14 }); 15 </script>
1 <div>div0</div> 2 <div>div1</div> 3 <div>div2</div> 4 <div>div3</div> 5 <script src="jQuery.js"></script> 6 <script> 7 $(function(){ 8 var $Div = $(‘div‘); 9 console.log($Div.eq(‘-1‘));// [0:div3,prevObject:$(‘div‘)] 10 console.log($Div.eq(-1));// [0:div3,prevObject:$(‘div‘)] 11 }); 12 </script>
标签:
原文地址:http://www.cnblogs.com/tyxloveyfq/p/4306042.html