这个 切片() 是jQuery中的一种内置方法,用于根据其索引选择元素子集。子集是一个集合,它可能是一个大集合的一部分。 语法:
null
$(selector).slice(para1, para2)
参数: 它接受下面指定的两个参数-
- 第1段: 它指定从何处开始选择图元。
- para2: 它是可选的,并指定停止选择图元的位置。
返回值: 它返回所选元素的子集。
显示slice()方法工作的jQuery代码:
< html > < head > < script </ script > <!-- jQuery code to show the working of this method --> < script > $(document).ready(function() { $("p").slice(1, 4).css("background-color", "lightgreen"); }); </ script > < style > body { width: 500px; height: 200px; padding: 20px; border: 2px solid green; } </ style > </ head > < body > < h1 >Welcome to GeeksforGeeks !</ h1 > < p >This is at index 0.</ p > < p >This is at index 1.</ p > < p >This is at index 2.</ p > < p >Tnhis is at index 3.</ p > </ body > </ html > |
输出: 在这段代码中,从索引1到3的所有段落元素都会高亮显示。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END