<!DOCTYPE html>
<html dir="ltr" lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>jQuery 表格自动增加</title>
<meta name="keywords" content="jQuery, 表格, table, 自动增加" />
<meta name="description" content="jQuery表格自动增加" />
<meta name="viewport" content="width=device-width" />
<meta name="copyright" content="imsole.net" />
<meta name="designer" content="sole" />
<meta name="publisher" content="imsole.net" />
<meta name="author" content="sole" />
<meta name="robots" content="all" />
<meta name="distribution" content="global" />
<style type="text/css">
table { width:900px; margin:50px auto; border-collapse:collapse; border-spacing:; }
table tr, table th, table td { border:1px solid #ddd; font-size:12px; }
table tr td:first-child { width:30px; text-align:center; }
table td input { width:%; height:%; padding:5px ; border: none; }
table td input:focus { box-shadow:1px 1px 3px #ddd inset; outline:none; }
table td a { display: block; width:30px; }
</style>
<body> <table id="count">
<tr><th>序号</th><th>姓名</th><th>金额[USD]</th><th>时间</th><th>项目</th><th>单位</th><th>备注</th><th>操作</th></tr>
<tr>
<td></td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td><input type="text" /></td>
<td><a href="javascript:;" class="del">删除</a></td>
</tr>
</table> <script src="http://apps.bdimg.com/libs/jquery/1.8.1/jquery.min.js"></script> <script type="text/javascript">
$(function(){ /* 这是一种方法,但是不精简,不过很好理解,就像面向过程编写代码一样。
var oTable = $("#count"), oTr = '', oInput = '', eEle = '';
oTable.on('mouseover', function(){
oTr = oTable.find('tr').last();
oInput = oTr.find('input');
eEle = oTr.clone();
oInput.on('click', function(){
var parent = $(this).parents('tr');
if(oTr.index() == parent.index()){
oTable.append(eEle);
}
});
});
*/ //这是第二种方法,比较精简,要看对jQ的理解了。
var oTable = $("#count"), iNum = , eEle = '';
oTable.on('click', function(e){
var target = e.target,
oTr = $(target).closest('tr');
if ($(target).hasClass('del') && oTr.index()>) {
iNum--;
var nextID = oTr.nextAll('tr').find('td:eq(0)');
nextID.each(function(i, ele){
$(ele).text( $(ele).text()- );
});
oTr.remove();
return;
};
if(oTr.index() == oTable.find('tr').last().index()){
iNum++;
eEle = oTr.clone();
eEle.find('td').eq().text(iNum);
}
oTable.append(eEle);
}); });
</script>
</body>
</html>

jQuery表格自动增加的更多相关文章

  1. jquery 表格自动拆分(方便打印)插件-printTable

    /** * jquery 表格打印插件 * * 作者: LiuJunGuang * 日期:2013年6月4日 * 分页样式(需要自定义): * @media print { * .pageBreak ...

  2. 基于jQuery表格增加删除代码示例

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 25款顶级的jQuery表格插件

    jQuery 表格插件可以让你创建各种各样的表格布局,表格布局是报纸和杂志中最常见的布局,现在的网站中也很常见,在这篇文章中,我向大家推荐25个jQuery 的表格插件,你可以任意控制表格的行和列,用 ...

  4. jQuery 表格插件25

    jQuery 表格插件可以让你创建各种各样的表格布局,表格布局是报纸和杂志中最常见的布局,现在的网站中也很常见,在这篇文章中,我向大家推荐25个jQuery 的表格插件,你可以任意控制表格的行和列,用 ...

  5. 25个顶级的jQuery表格插件

    jQuery 表格插件可以让你创建各种各样的表格布局,表格布局是报纸和杂志中最常见的布局,现在的网站中也很常见,在这篇文章中,我向大家推荐25个jQuery 的表格插件,你可以任意控制表格的行和列,用 ...

  6. Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引

    因为内容比较多,所以每篇讲解一些内容,最后会放出全部代码,可以参考.操作中总会遇到各式各样的问题,个人对部分问题的研究在最后一篇 问题研究 里.欢迎大家探讨学习. 代码都经过个人测试,但仍可能有各种未 ...

  7. Web jquery表格组件 JQGrid 的使用 - 11.问题研究

    系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...

  8. Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数、ColModel API、事件及方法

    系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...

  9. Web jquery表格组件 JQGrid 的使用 - 5.Pager翻页、搜索、格式化、自定义按钮

    系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...

随机推荐

  1. 7) mvn dependency:tree

    http://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html mvn dependency:tree 查看 <de ...

  2. 整理iOS9适配中出现的坑

    一.NSAppTransportSecurity iOS9让所有的HTTP默认使用了HTTPS,原来的HTTP协议传输都改成TLS1.2协议进行传输.直接造成的情况就是App发请求的时候弹出网络无法连 ...

  3. PrefixHeader.pch 在工程中的使用

    1)  新建一个pch文件 2) 在 工程 Build Settings 中搜索 header  将Precompile Prefix Header 置为YES 2) 选中pch文件, 将右侧相对路径 ...

  4. Windows环境下的安装gcc

    Windows具有良好的界面和丰富的工具,所以目前linux开发的流程是,windows下完成编码工作,linux上实现编译工作. 为了提高工作效率,有必要在windows环境下搭建一套gcc,gdb ...

  5. hdu 5066 小球碰撞(物理题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5066 中学物理题 #include <cstdio> #include <cstdlib> ...

  6. hdu 4952 暴力

    http://acm.hdu.edu.cn/showproblem.php?pid=4952 给定x,k,i从1到k,每次a[i]要是i的倍数,并且a[i]大于等于a[i-1],x为a0 递推到下一个 ...

  7. Why I Want A Wife

    I want a wife who will take care of my physical needs. I want a wife who will keep my house clean. A ...

  8. 评论:一套Developer Express控件包 For Delphi7

    http://www.2ccc.com/idea.asp?articleid=1675 (也可以查看盒子上这个帖子的内容) Developer Express Inc 系列控件组 for Delphi ...

  9. 挂载Linux云主机硬盘到本地计算机

      现在移动硬盘已经是每个人的生活必需品了,当然网络也是我们生活的必需品,我们现在就是要用网络存储代替硬盘存储,当然再实际使用过程中需要考虑到以下两个问题: 网络延迟 云主机磁盘IO   以上两个关键 ...

  10. Gitlab搭建安装及使用中遇到的问题。

    一.CentOS7安装gitlab-ce 1.下载及安装rpm软件包. 下载RPM包 curl -LJO https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ ...