jQuery操作table tr td
1.鼠标移动行变色
$("#tab tr").hover(function(){
$(this).children("td").addClass("hover")
},function(){
$(this).children("td").removeClass("hover")
});
方法二:
$("#tab tr:gt(0)").hover(function(){
$(this).children("td").addClass("hover");
},function(){
$(this).children("td").removeClass("hover");
});
2.奇偶行不同颜色
$("#tab tbody tr:odd").css("background-color","#bbf");
$("#tab tbody tr:even").css("background-color","#fff");
$("#tab tbody tr:odd").addClass("odd");
$("#tab tbody tr:even").addClass("even");
3.隐藏一行
$("#tab tbody tr:eq(3)").hide();
4.隐藏一列
$("tab tr td::nth-child(3)").hide(); 方法二 $("tab tr").each(function(){
$("td:eq(3)",this).hide();
});
5.删除一列
//删除除第一列所有列
$("#tab tr th:not(:nth-child(1))").remove();
$("#tab tr td:not(:nth-child(1))").remove();
//删除第一列
$("#tab tr td::nth-child(1)").remove();
6.删除一行
//删除除第一行所有行
$("#tab tr :not(:first)").remove();
//删除指定行
$("#tab tr:eq(3)").remove();
7.得到(设置)某个单元格的值
//设置tab 第2个tr的第一个td的值。
$("#tab tr:eq(1) td:nth-child(1)").html("value");
//获取tab 第2个tr的第一个td的值
$("tab tr:eq(1) th:nth-child(1)).html();
8.插入一行
//插入一行
$("<tr><td>插入3</td><td>插入</td></tr>").insertAfter("#tab tr:eq(1)");
9.获取每一行单元格的值
var arr=[];
$("tab tr td:nth-child(1)").each(function(key,value){
arr.push($(this).html());
});
var result = arr.join(',');
10.遍历tab tr获取td的值实现方法
<tbody id="history_income_list">
<tr>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><a class="" onclick="history_income_del(this);" href="###">删除</a></td>
</tr>
<tr>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><a class="" href="###">删除</a></td>
</tr>
<tr>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><a class="" href="###">删除</a></td>
</tr>
</tbody>
//方法1
var trList = $("#history_income_list").children("tr")
for (var i=0;i<trList.length;i++) {
var tdArr = trList.eq(i).find("td");
var history_income_type = tdArr.eq(0).find("input").val();//收入类别
var history_income_money = tdArr.eq(1).find("input").val();//收入金额
var history_income_remark = tdArr.eq(2).find("input").val();// 备注 alert(history_income_type);
alert(history_income_money);
alert(history_income_remark);
}
//方法2
$("#history_income_list").find("tr").each(function(){
var tdArr = $(this).children();
var history_income_type = tdArr.eq(0).find("input").val();//收入类别
var history_income_money = tdArr.eq(1).find("input").val();//收入金额
var history_income_remark = tdArr.eq(2).find("input").val();// 备注 alert(history_income_type);
alert(history_income_money);
alert(history_income_remark); });
11.根据tab中td所在的行号或列号
//获取表的总数tr
$("#table").find("tr").length;
//获取所在的行号
$("#td1").parent().prevAll().length+1
//获取所在的列号
$("#td1").prevAll().length+1;
jQuery操作table tr td的更多相关文章
- jQuery操作Table tr td常用的方法
虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...
- 汇总常用的jQuery操作Table tr td方法
虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...
- jQuery遍历Table tr td td中包含标签
function shengchen() { var arrTR = $("#tbModule").children(); var Context=""; $( ...
- JQuery操作Table元素
使用Jquery操作Table中的tr向上或向下移动,以及全选和反选操作. 点击Table Head中的复选框,全选或反选表格中所有的复选框; 选中复选框,点击Up 按钮, tr上移;点击 Down ...
- jQuery操作table数据上移、下移和置顶
jQuery 操作table中的tr换行的步骤如下: 1.获取当前tr var $tr = $(this).parents("tr"); 2.移动tr //上移 $tr.prev( ...
- JS动态创建Table,Tr,Td并赋值
JS动态创建Table,Tr,Td并赋值. 成果库修改: 要求主题列表随成果类型改变而改变 网上查询资料后开工,在成果类型下拉框添加change()事件触发Dwr,查询主题集合——动态创建/编辑Tab ...
- html中table,tr,td
table表格,tr表格中的行,tr表格中的列,等级关系是table>tr>td, 当然表格中还包括thead,tbody,tfoot,th,但由于浏览器支持缘故很少使用.另外table在 ...
- Jquery操作Table
Jquery 操作 Html Table 是很方便的,这里对表格的基本操作进行一下简单的总结. 首先建立一个通用的表格css 和一个 表格Table: table { border-collapse: ...
- jQuery操作Table学习总结[转]
<style type="text/css"> .hover { } </style>< ...
随机推荐
- apache配置文件详解与优化
apache配置文件详解与优化 一.总结 一句话总结:结合apache配置文件中的英文说明和配置详解一起看 1.apache模块配置用的什么标签? IfModule 例如: <IfModule ...
- 雷林鹏分享:Ruby CGI 编程
Ruby CGI 编程 Ruby 是一门通用的语言,不仅仅是一门应用于WEB开发的语言,但 Ruby 在WEB应用及WEB工具中的开发是最常见的. 使用Ruby您不仅可以编写自己的SMTP服务器,FT ...
- ajax方法携带授权标识
$.ajax({ type: "post", url: "/api/login", data: { username: getusername, passwor ...
- Docker环境准备-安装Ubuntu
***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***
- hdu2177威佐夫博弈
输的话输出0,赢就输出1并且输出第一步走后的数目 威佐夫博弈判断胜负 原理及常见题型求法: http://blog.csdn.net/y990041769/article/details/216940 ...
- UVA-11082 Matrix Decompressing (网络流建模)
题目大意:给出一个由1到20组成的整数矩阵的每一行和每一列的和,构造这个矩阵.输出任意一个构造方案. 题目分析:将每一行视作一个点x,将每一列视作一个点y.对于矩阵中的每一个格子,都对应一个二元关系& ...
- jspf、jsp小记
jsp页面:
- 高并发数据采集的架构应用(Redis的应用)
问题的出发点: 最近公司为了发展需要,要扩大对用户的信息采集,每个用户的采集量估计约3W.如果用户量增加的话,将会大量照成采集量成3W倍的增长,但是又要满足日常业务需要,特别是报表数据必要 ...
- 中行用户购买KIS2014 68元/3年,时间:2013.10.18-2013.11.18
活动地址:http://boc.kaba365.com/4989800.asp
- 解析xml(当节点中有多个子节点)
概要:解析一个xml,当一个节点中又包含多个子节点如何解析,对比一个节点中不包括其他节点的情况. 一,xml样例 <cisReports batNo="查询批次号" unit ...