jQuery slice()เมธอด

❮ วิธีการข้ามผ่าน jQuery

ตัวอย่าง

เริ่มการเลือก <p> องค์ประกอบจาก <p> องค์ประกอบที่มีดัชนีหมายเลข 2:

$("p").slice(2)

ความหมายและการใช้งาน

วิธี slice() เลือกชุดย่อยขององค์ประกอบตามดัชนี

เซตย่อยคือเซตที่เป็นส่วนหนึ่งของเซตที่ใหญ่กว่า

วิธีนี้ใช้เพื่อจำกัดการเลือกองค์ประกอบในกลุ่มโดยจุดเริ่มต้นและจุดสิ้นสุด: พารามิเตอร์ เริ่มต้นคือดัชนีเริ่มต้น (เริ่มต้นที่ 0) ซึ่งจะสร้างชุดย่อย และ พารามิเตอร์ หยุดเป็นจุดสิ้นสุดทางเลือก


ไวยากรณ์

$(selector).slice(start,stop)

Parameter Description
start Required. Specifies where to start the selection of elements. The index numbers start at 0.

Note: Using a negative number will select elements from the end of the selected elements, instead of the beginning.
stop Optional. Specifies where to end the selection of elements. If omitted, the selection continues until the end of the set. The index numbers start at 0.

Note: Using a negative number will select elements from the end of the selected elements, instead of the beginning.

ลองด้วยตัวคุณเอง - ตัวอย่าง


วิธีใช้พารามิเตอร์ทั้งสองเพื่อเลือก <p> องค์ประกอบจากจุดเริ่มต้นและจุดสิ้นสุด


การใช้จำนวนลบเพื่อเริ่มต้นการเลือกองค์ประกอบ <p> นับจากจุดสิ้นสุด แทนที่จะเป็นจุดเริ่มต้น


การใช้การเริ่มต้นและหยุดด้วยจำนวนลบเพื่อเริ่มการเลือกองค์ประกอบ <p> นับจากจุดสิ้นสุด


❮ วิธีการข้ามผ่าน jQuery