Description

The slice( start, end ) method selects a subset of the matched elements.

Syntax

Here is the simple syntax to use this method −

selector.slice( start, end )

Parameters

Here is the description of all the parameters used by this method −

  • start − Where to start the subset. The first element is at zero. Can be negative to start from the end of the selection.

  • end − Where to end the subset excluding end element. If unspecified, ends at the end of the selection.

Example

Following is a simple example a simple showing the usage of this method −

<html><head><title>The jQuery Example</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script type="text/javascript" language="javascript">$(document).ready(function() {$("li").slice(2, 5).addClass("selected");});</script><style>.selected { color:red; }</style></head><body><div><ul><li class="above">list item 0</li><li class="top">list item 1</li><li class="top">list item 2</li><li class="middle">list item 3</li><li class="middle">list item 4</li><li class="bottom">list item 5</li><li class="bottom">list item 6</li><li class="below">list item 7</li></ul></div></body>
</html>

  

This will produce following result −

<html><head><title>The jQuery Example</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script type="text/javascript" language="javascript">$(document).ready(function() {$("li").slice(2, 5).addClass("selected");});</script><style>.selected { color:red; }</style></head><body><div><ul><li class="above">list item 0</li><li class="top">list item 1</li><li class="selected">list item 2</li><li class="selected">list item 3</li><li class="selected">list item 4</li><li class="bottom">list item 5</li><li class="bottom">list item 6</li><li class="below">list item 7</li></ul></div></body>
</html>

  

This will produce following result −

转载于:https://www.cnblogs.com/hephec/p/4574423.html

jQuery - slice( start, [end] ) Method相关推荐

  1. 点击“换一换”切换商品,使用jquery slice()实现无缝连接切换

    页面需求需要做一个点击换一换按钮,切换商品信息.网上看了一些笨方法,觉得太冗余.自己写了一个精简版的如下: html部分 <div class="layer clearfix qian ...

  2. slice()如何在jQuery中工作

    Earlier we looked how to get an element with specific index in jQuery, but sometimes we want to get ...

  3. jquery教程_jQuery教程

    jquery教程 I have written a lot of jQuery tutorial articles. This is an index post for all the jQuery ...

  4. HTML中动态图片切换JQuery实现

     相信很多同学都注意到了,各大新闻或者娱乐网站都含有动态图片切换,那个漂亮的感觉让刚刚学习html的人,都非常好奇和心动.那下面就让我们看一下到底如何实现动态图片切换呢?看一下百度贴吧的效果图吧~ ...

  5. jquery学习手记(10)事件简介

    1. 使用jquery监听的方法有许多种: // The many ways to bind events with jQuery // Attach an event handler directl ...

  6. 封装jQuery下载文件组件

    使用jQuery导出文档文件 jQuery添加download组件 jQuery.download = function(url, data, method){if( url && d ...

  7. JavaScript学习笔记(四)——jQuery插件开发与发布

    jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...

  8. Golang Clearing slice

    //first method :slice = nil// second method :slice = slice[0:0] Source page : https://www.socketloop ...

  9. Jquery+asp.net实现Ajax方式文件下载实例代码

    如果文件中,需要下载一个文件,一般用超级链接的方式即可. 但是如果是图片,浏览器会默认打开图片浏览,不是实现下载. 考虑可以使用jquery ajax提交form请求的方式. jquery downl ...

  10. jquery position

    在给元素定位之前,我们首先要了解一些CSS定位相关的知识. 在CSS中关于定位的内容是:position:relative | absolute | static | fixed .static 没有 ...

最新文章

  1. mysql5.7安装教程图文详解
  2. Dcoker(系列) docker-redis警告处理
  3. https://www.unimelb.edu.au/
  4. 未指定发送trap的源接口_组播之RPF接口检测
  5. Codeforces 558E A Simple Task
  6. Asp.Net Core 2.2.0-preview1已经发布
  7. 【APICloud系列|33】移动应用软件加固步骤,适合所有的安卓应用市场
  8. es6关于let和const的总结
  9. java国际化服务器不识别_国际化踩坑记录java.util.MissingResourceException:
  10. 【语义分割】全卷积网络(Fully Convolutional Networks, FCN)详解
  11. 隔壁桌的美女同事问我,凭啥子Nginx的并发数可以达到3w?我这次被打脸了~
  12. 【优化算法】贪婪策略和变异策略的混合蚁群算法【含Matlab源码 1521期】
  13. Java 实现 HTML 转 PDF 文件
  14. A Style-Aware Content Loss for Real-time HD Style Transfer(一个风格转换的风格感知损失)CVPR2018
  15. 基于Vue的单页面格式化数据高亮编辑器组件:兼容json/xml/html/txt多种格式
  16. 去哪儿网2018春招软件开发工程师、前端开发工程师编程题 - 题解
  17. 2017小象学院Python数据分析与挖掘
  18. 换行和禁止换行及超出省略号
  19. 在线Base64编码 = 图片
  20. smss.exe之wom毒

热门文章

  1. Hive启动的三种方式
  2. Hbase二级索引入门
  3. Cmake构建_指定gcc/g++版本
  4. JAVA发送HttpClient请求及接收请求结果过程
  5. Output error file to the following location:[ A:\GHOST ERR.TXT] 错误处理
  6. 读《世界是数字的》有感③
  7. Linux下使用rsync最快速删除海量文件的方法分享
  8. 【Iphone 游戏开发之一】创建视图并绘制简单图形
  9. redis的批量操作命令pipeline(PHP实现)
  10. sublime3环境