当前位置:网站首页>jq怎么获取倒数的元素
jq怎么获取倒数的元素
2022-06-27 05:02:00 【前端切图仔Zz】
<ul>
<li>倒数第四个</li>
<li>倒数第三个</li>
<li>倒数第二个</li>
<li>倒数第一个</li>
</ul>
jq获取最后一个元素:
var text = $('ul li').last().text()
console.log(text)
打印结果:
jq获取倒数第二个元素:
var text = $('ul li').eq(-2).text()
console.log(text)
打印结果:
拓展:
eq() 方法 :返回带有被选元素的指定索引号的元素。
语法
$(selector).eq(index)
index 必需要有,用以规定元素的索引。可以是整数或负数。其中,使用负数将从被选元素的结尾开始计算索引。
边栏推荐
- Mobilenet series (4): mobilenetv3 network details
- 018 C语言基础:C文件读写
- 010 C language foundation: C function
- Microservice system design - service fusing and degradation design
- Nignx configuring single IP current limiting
- 深潜Kotlin协程(十五):测试 Kotlin 协程
- Microservice system design -- microservice invocation design
- Cultural tourism light show breaks the time and space constraints and shows the charm of night tour in the scenic spot
- 011 C语言基础:C作用域规则
- [unity] button of UI interactive component & summary of optional base classes
猜你喜欢

Redis high availability cluster (sentry, cluster)

快速排序(非遞歸)和歸並排序

Microservice system design -- service registration, discovery and configuration design

日志收集系统

Building lightweight target detection based on mobilenet-yolov4
![Golang Hello installation environment exception [resolved]](/img/30/bddba695e4c0059102e86de346b58d.png)
Golang Hello installation environment exception [resolved]

机械转码日记【17】模板,STL简介

Microservice system design -- distributed cache service design

微服务系统设计——分布式定时服务设计

Why does C throw exceptions when accessing null fields?
随机推荐
009 basics of C language: C loop
011 C语言基础:C作用域规则
【C语言】关键字的补充
019 basics of C language: C preprocessing
重映像(STM32)
013 C语言基础:C指针
nignx配置单ip限流
013 basics of C language: C pointer
[station B up dr_can learning notes] Kalman filter 3
Laptop does not have WiFi option solution
IOS development: understanding of dynamic library shared cache (dyld)
021 basics of C language: recursion, variable parameters
Golang Hello installation environment exception [resolved]
MySql最详细的下载教程
流媒体协议初探(MPEG2-TS、RTSP、RTP、RTCP、SDP、RTMP、HLS、HDS、HSS、MPEG-DASH)
《数据库原理与应用》第一版 马春梅……编著 期末复习笔记
快速排序(非递归)和归并排序
差点因为 JSON.stringify 丢了奖金...
020 basics of C language: C language forced type conversion and error handling
math_数集(数集符号)和集合论