首页 > 其他 > 详细

$("selector").slice(start, end)

时间:2015-06-14 00:24:29      阅读:225      评论:0      收藏:0      [点我收藏+]

$("selector").slice(start, end) slices matched set into subset specified by start and optional end.

Example 1: $("div").slice(0,1) will first find all <div> then slice the mathced set into subset starting from element at index=0 and ending "but NOT including" elment at index=1.

<div>A</div>  // index = 0 
<div>B</div>  // index = 1 
<div>C</div>

  

Matched set is a set of elements matching selector. For example, in Example 1 matchted set is set of elements matching $("div") selector
<p>p-1</p>
<div id=‘someID‘>div-1</div> //index = 0
<div class=‘someClass‘>div-2</div> //index = 1
<div>div-3</div> //index = 2
<span>span-1</span>

  

Example 2: $("div").slice(1) will first find all <div> then slice the mathced set into subset starting from element at index=1 to the last element.

<div>A</div>  // index = 0 
<div>B</div>  // index = 1 
<div>C</div>  // index = 2 

  

Example 3: $("div").slice(-2) will first find all <div> then slice the mathced set into subset starting from element at index=-2 "second element from the last" to the last element.

<div>A</div>  // index = 0 & index = -3 from last 
<div>B</div>  // index = 1 & index = -2 from last 
<div>C</div>  // index = 2 & index = -1 from last 

  

$("selector").slice(start, end)

原文:http://www.cnblogs.com/hephec/p/4574412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!