slice (start, [end]) to select a subset matching with the original slice method analogous

slice(start, [end])

Outline

Select a subset of matching

The method is similar to the original slice

parameter

startIntegerV1.1.4

Select the start position of the subset. The first element is 0. If it is negative, you can choose to start from the tail of the collection. Marble platform test procedures

end Integer V1.1.4

Select the end of their position, if not specified, then that is the end itself.

Examples

description:

Select the first p element

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
$("p").slice(0, 1).wrapInner("<b></b>");
result:
[ <p><b>Hello</b></p> ]

description:

Select the first two elements p

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
$("p").slice(0, 2).wrapInner("<b></b>");
result:
[ <p><b>Hello</b></p>,<p><b>cruel</b></p> ]

description:

Select only the second p element

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
$("p").slice(1, 2).wrapInner("<b></b>");
result:
[ <p><b>cruel</b></p> ]

description:

Select only the second and third elements p

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
$("p").slice(1).wrapInner("<b></b>");
result:
[ <p><b>cruel</b></p>, <p><b>World</b></p> ]

description:

Finally, select the first element of a p

HTML code:
<p>Hello</p><p>cruel</p><p>World</p>
jQuery code:
$("p").slice(-1).wrapInner("<b></b>");
result:
[ <p><b>World</b></p> ]

Guess you like

Origin www.cnblogs.com/furuihua/p/12012529.html