当前位置:网站首页>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 必需要有,用以规定元素的索引。可以是整数或负数。其中,使用负数将从被选元素的结尾开始计算索引。
边栏推荐
- 006 C language foundation: C storage class
- Penetration test - file upload / download / include
- Cultural tourism night tour | stimulate tourists' enthusiasm with immersive visual experience
- Fastdds server records - Translation-
- 机械转码日记【17】模板,STL简介
- neo4j图数据库基本概念
- 010 C语言基础:C函数
- Building lightweight target detection based on mobilenet-yolov4
- 什么是BFC?有什么用?
- Redis high availability cluster (sentry, cluster)
猜你喜欢

【C语言】关键字的补充

清华大学开源软件镜像站网址

Redis high availability cluster (sentry, cluster)

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

Edge在IE模式下加载网页 - Edge设置IE兼容性

躲避小行星游戏

Microservice system design -- microservice monitoring and system resource monitoring design

Microservice system design - service fusing and degradation design

Building lightweight target detection based on mobilenet-yolov4

Microservice system design -- distributed cache service design
随机推荐
022 basics of C language: C memory management and C command line parameters
Microservice system design -- microservice invocation design
真xx相来了?测试/开发程序员为什么不愿意加班,这是个疯狂的状态......
DAST 黑盒漏洞扫描器 第六篇:运营篇(终)
leetcode-20. Valid parentheses -js version
Is the truth XX coming? Why are test / development programmers unwilling to work overtime? This is a crazy state
Fastdds server records - Translation-
unity点光源消失
013 basics of C language: C pointer
Microservice system design -- Distributed timing service design
【Unity】UI交互组件之按钮Button&可选基类总结
Laptop does not have WiFi option solution
Cultural tourism night tour | stimulate tourists' enthusiasm with immersive visual experience
Kotlin compose custom compositionlocalprovider compositionlocal
Almost because of json Stringify lost his bonus
018 C语言基础:C文件读写
从某种意义来讲,互联网业已成为了一个孵化器,一个母体
系统架构设计——互联网金融的架构设计
Mobilenet series (4): mobilenetv3 network details
neo4j图数据库基本概念