jq根据table的tr行数动态删除相应的行
2024-08-20 14:01:18
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body> <table id="tableId" class="123">
<tr >
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td><button>删除</button></td>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
<td><button>删除</button></td>
</tr>
<tr>
<td>e</td>
<td>f</td>
<td>g</td>
<td>h</td>
<td><button>删除</button></td>
</tr>
<tr>
<td>i</td>
<td>j</td>
<td>k</td>
<td>l</td>
<td><button>删除</button></td>
</tr> </table> <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
window.onload=function() { $("table td button").click(function () {
var row = $(this).parent().parent().index(); // 行位置
console.log("当前行", row);
var allnum = $("table").find("tr").length; //获取总共有多少tr
console.log("all", allnum); for (i = allnum; i >= row; i--) {
if (i == allnum) {
last_index = allnum - 1;
console.log("最后一个", last_index);
$("table tr:eq(" + last_index + ")").remove(); }
else {
console.log("----", i);
$("table tr:eq(" + i + ")").remove(); };
};
}); }
</script>
</body>
</html>
最新文章
- spring整合mybatis使用<;context:property-placeholder>;时的坑
- [LeetCode] Climbing Stairs 爬梯子问题
- How to build .apk file from command line(转)
- python 学习笔记7 面向对象编程
- 【PC网站前端架构探讨系列】结合公司网站首页,谈前端模块化开发与网站性能优化实践
- 用eclipse碰到的一些错误,然后自己去网上找的解决办法
- 一文让你彻底了解iOS字体相关知识
- 1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost
- 微软职位内部推荐-Senior Software Engineer -Web
- SQL和NOSQL有区别吗?
- Xamarin IOS – hello word
- Cocos2d Lua 越来越小样本 内存游戏
- 第 1 章 Node.js 介绍
- Java 基础 JRE和JDK的区别
- Python机器学习(基础篇---监督学习(支持向量机))
- .net MVC使用NPOI读取Excel模板,再写入数据
- web中的集群与分布式
- TWebBrowser禁止弹出Alert对话框
- c#异步等待
- Linux常用rmp包网址
热门文章
- Spring Boot2 系列教程 (八) | 配置日志
- dubbo配置文件解读(2)
- playbooks框架部署远程主机
- 【新书推荐】《ASP.NET Core微服务实战:在云环境中开发、测试和部署跨平台服务》 带你走近微服务开发
- [UVA1494] Qin Shi Huang&#39;s National Road System
- java面试| 线程面试题集合
- azure 第一弹
- Spring Cloud Alibaba 之 Sentinel 限流规则和控制台实例
- Navicat premium 12 for mac 无限试用
- SpringBoot缓存篇Ⅰ--- 缓存抽象