超级简单的jquery操作表格(添加/删除行、添加/删除列)
利用jquery给指定的table添加一行、删除一行
<script language="javascript" src="./jquery.js"></script>
<table border="1px #ooo" id="test" name="test" class="test" cellpadding="0" cellspacing="0" width="20%">
<tr id="1"><td width="30%">1</td>
<td width="30%">2</td>
<td width="30%">3</td></tr>
<tr id="2"><td width="30%">11</td>
<td width="30%">22</td>
<td width="30%">33</td></tr>
</table>
<table border="1px #ooo" id="test1" name="test1" cellpadding="0" cellspacing="0" width="20%"> <tr id="4"><td width="30%">1</td>
<td width="30%">2</td>
<td width="30%">3</td>
</tr>
</table>
<input type="button" name="button" value="add" onclick="addtr('test');">
<input type="button" name="button" value="del" onclick="deltr('test');">
<script> //在id为test的table的最后增加一行
function addtr(id){ tr_id = $("#test>tbody>tr:last").attr("id");
tr_id++; //alert(tr_id);
str = "<tr id = '"+tr_id+"'><td width='30%'>re1</td><td width='30%'>re2</td><td width='30%'>re3</td></tr>";
$('#'+id).append(str); } //删除id为test的table的最后一行
function deltr(id){ tr_id = $("#test>tbody>tr:last").attr("id"); $('#'+tr_id).remove();
}
</script>
jQuery动态添加删除表格的行和列
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css"> .cl1{ background-color:#FFFFFF; } .cl2{ background-color:#FFFF99; } </style>
<script type="text/javascript" src="css_js/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
var rowCount = 0;
var colCount = 2;
function addRow(){ rowCount++; var rowTemplate = '<tr class="tr_'+rowCount+'"><td>'+rowCount+'</td><td class="cl1">内容'+rowCount+'</td><td class="cl1"><a href="#" onclick=delRow('+rowCount+')>删除</a></td></tr>';
var tableHtml = $("#testTable tbody").html();
tableHtml += rowTemplate; $("#testTable tbody").html(tableHtml); }
function delRow(_id){ $("#testTable .tr_"+_id).hide(); rowCount--; }
function addCol(){ colCount++; $("#testTable tr").each(function(){
var trHtml = $(this).html(); trHtml += '<td onclick="delCol('+colCount+')">增加的td</td>';
$(this).html(trHtml);
});
}
function delCol(_id){ $("#testTable tr").each(function(){ $("td:eq("+_id+")",this).hide(); });
colCount--;
}
function mover(_id){ $("#testTable tr:not(:first)").each(function(){ $("td:eq("+_id+")",this).removeClass("cl1");
$("td:eq("+_id+")",this).addClass("cl2"); }); }
function mout(_id){ $("#testTable tr:not(:first)").each(function(){ $("td:eq("+_id+")",this).removeClass("cl2");
$("td:eq("+_id+")",this).addClass("cl1"); }); } </script> <title>jquery操作表格测试</title>
</head>
<body>
<table id="testTable" border="1" width="500"> <tr>
<td>序号</td> <td onmouseover="mover(1);" onmouseout="mout(1);">内容</td>
<td onmouseover="mover(2);" onmouseout="mout(2);">操作</td> </tr>
</table>
<input type="button" value="添加行" onclick="addRow();"/>
<input type="button" value="添加列" onclick="addCol();"/>
</body>
jquery操作表格(添加/删除行、添加/删除列) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<title>jquery操作表格测试</title>
<script type="text/javascript">
function del(_id){ $("#testTable .tr_"+_id).html('');
var tableTr = $("#testTable .tr_"+_id).hide(); }
function addRow(){ var addRowTemplete = '<tr class="tr_'+tableCount+'">
<td class="cl1">'+tableCount+'</td><td class="cl1">内容'+tableCount+'</td>
<td class="cl1"><a href="javascript:void(0)" onclick=del('+tableCount+');>删除</a></td></tr>'; $("#testTable tbody").append(addRowTemplete); } function addCol(){ $("#testTable tr").each(function(){ var trHtml = "<td onclick='delCol("+colCount+")'>曾加的td</td>"; $(this).append(trHtml); }); } function delCol(_id){ $("#testTable tr").each(function(){ $("td:eq("+_id+")",this).hide(); }); }
</script> </head>
<body>
<table width="487" border="1" id="testTable"> <tr> <td onclick="delCol(0)">序号</td> <td onclick="delCol(1)">内容</td> <td onclick="delCol(2)">操作</td> </tr> </table> <p> <input type="button" name="Submit" value="添加行" onclick="addRow()" /> <input type="button" name="Submit2" value="添加列" onclick="addCol()"/> </p> </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>我的百分之一女装店官方网站|白菜园社区|4000-921001|就爱百分一</title>
<meta name="keywords" content="我的百分之一,我的百分之一女装店,我的百分之一商城,我的百分之一淘宝" />
<meta name="description" content="我的百分之一淘宝三金冠女装店官方网站100f1.com,仅为百分一有品位的美女!我的百分之一商城每月发布新款时尚女装和潮流服饰女装搭配。" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
</head>
<body>
<div id="wrap" class="wrap">
<div class="fatie" id="fatie">
<dl class="options">
<dd>选项<span>1</span>:<input type="text" class="text" /><a class="base_icon" href="javascript:void(0);">删除</a></dd>
<dd>选项<span>2</span>:<input type="text" class="text" /><a class="base_icon" href="javascript:void(0);">删除</a></dd>
<dd>选项<span>3</span>:<input type="text" class="text" /><a class="base_icon" href="javascript:void(0);">删除</a></dd>
<dd>选项<span>4</span>:<input type="text" class="text" /><a class="base_icon" href="javascript:void(0);">删除</a></dd>
<dd>选项<span>5</span>:<input type="text" class="text" /><a class="base_icon" href="javascript:void(0);">删除</a></dd>
</dl>
<p class="add_opt">
<span class="base_icon">添加更多选项</span>
</p>
</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){//投票选项增减控制
var fatie = $("#fatie");
var option = fatie.find(".options dd");
function list_again(){//选项重新排序
option.each(function(){
var i = $(this).index();
$(this).find("span").html(i+1);
})
}
fatie.find(".add_opt span").click(function(){//增加选项
fatie.find(".options").append('<dd>选项<span>i</span>:<input type="text" class="text" /><a class="base_icon" href="javascript:void(0);">删除</a></dd>');
option = fatie.find(".options dd");
list_again();
})
option.find("a").live("click",function(){//删除选项
$(this).parent().remove();
list_again();
})
})
</script>
</html>
超级简单的jquery操作表格(添加/删除行、添加/删除列)的更多相关文章
- Jquery操作表格多出一个内容行
目录 前言 需求 如何监听每一行点击,获取点击id 前后端 问题更新,ajax异步带来的问题 废弃使用HTML拼接 前言 我的前端实在是太差劲了,导致Jquery操作表格多出一个内容行,这个功能我都做 ...
- jQuery操作表格(table)的常用方法、技巧汇总
摘录自:http://www.jb51.net/article/48943.htm 虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便 ...
- 超级简单的jQuery纯手写五星评分效果
超级简单的评分功能,分为四个步骤轻松搞定: 第一步: 引入jquery文件:这里我用百度CDN的jquery: <script src="http://apps.bdimg.com/l ...
- jquery操作表格 合并单元格
jquery操作table,合并单元格,合并相同的行 合并的方法 $("#tableid").mergeCell({ cols:[X,X] ///参数为要合并的列}) /** * ...
- jquery动态表格,动态添加表格行
转载收藏于:https://www.cnblogs.com/zhangqs008/archive/2013/05/09/3618459.html 效果图: Html:<html> &l ...
- 第七章 jQuery操作表格及其它应用
1.表格变色 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org ...
- jquery操作表格总结
返回表格行 或 列的索引 td是列,tr是行: <script type="text/javascript"> $(document).ready(function() ...
- jquery 操作表格实例
案例1:隔行变色,滑动,点击变色以(选中取消效果)(addClass(),removeClass(),toggleClass()) Html: <h4>1.隔行变行</h4> ...
- 超级简单的jquery轮播图demo
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
随机推荐
- 解问 lambda表达式
目录 1.0 何为Lambda 1.1 Lambda语法特征 1.2 Lambda实例 1.3 Lambda中的stream 1.4 Lambda 中的 stream 效率 1.0 何为Lambda ...
- JAVAEE——Lucene基础:什么是全文检索、Lucene实现全文检索的流程、配置开发环境、索引库创建与管理
1. 学习计划 第一天:Lucene的基础知识 1.案例分析:什么是全文检索,如何实现全文检索 2.Lucene实现全文检索的流程 a) 创建索引 b) 查询索引 3.配置开发环境 4.创建索引库 5 ...
- python学习笔记 - for循环: 遍历字典, 分别打印key, value, key:value
#遍历字典, 分别打印key, value, key:value emp = {'name':'Tom', 'age':20, 'salary' : 8800.00} for k in emp.key ...
- 【BZOJ 3036】 3036: 绿豆蛙的归宿 (概率DP)
3036: 绿豆蛙的归宿 Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 491 Solved: 354 Description 随着新版百度空间的下线 ...
- 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution
题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...
- 【Codeforces528D】Fuzzy Search FFT
D. Fuzzy Search time limit per test:3 seconds memory limit per test:256 megabytes input:standard inp ...
- 【BZOJ-3527】力 FFT
3527: [Zjoi2014]力 Time Limit: 30 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 1544 Solved: 89 ...
- Android设备运用Clockworkmod Recovery恢复模式安装定制的Rom
Clockworkmod Recovery是一个由Cyanogen团队开发的用于Android设备的第三方定制Recovery恢复模式,也称为CWM Recovery,具体它有什么用处呢?请看关于Go ...
- SQL 脚本中的全角逗号引起【ORA-01756: 引号内的字符串没有正确结束】
今天运行壹個小程序,功能是读取指定目录下的 SQL 脚本,并加载到内存中批量执行,之前的程序运行良好.但是今天相关开发人员更新了其中壹個 SQL 脚本,于是程序运行的时候就出错了,错误提示信息如下:批 ...
- GIT 详解2
https://segmentfault.com/a/1190000000738398 http://www.cnblogs.com/cposture/p/4903767.html https://g ...