专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > jQuery

基于jQuery报表增加删除代码

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
基于jQuery表格增加删除代码

基于jQuery表格增加删除代码是一款动态增加删减表格行特效代码。效果图如下:

在线预览    源码下载

实现的代码。

html代码:

<div style="width:720px;margin:20px auto;">
      <table id="tab11" style="display: none">
          <tbody>
              <tr>
                  <td height="30" align="center">
                      <input type="text" name="NO" size="2" value="1" />
                  </td>
                  <td align="center">
                      <input type="text" name="start_end_time" />
                  </td>
                  <td align="center">
                      <input type="text" name="unit_department" />
                  </td>
                  <td align="center">
                      <input type="text" name="post" />
                  </td>
                  <td>
                      <input type="button" id="Button1" onclick="deltr(this)" value="删行" />
                  </td>
              </tr>
          </tbody>
      </table>
      <input type="button" id="btn_addtr" value="增行" />
      <table id="dynamicTable" width="700" border="0" cellspacing="0" cellpadding="0">
          <thead>
              <tr>
                  <td height="30" align="center" bgcolor="#CCCCCC">ID</td>
                  <td align="center" bgcolor="#CCCCCC">起止时间</td>
                  <td align="center" bgcolor="#CCCCCC">单位/部门</td>
                  <td align="center" bgcolor="#CCCCCC">职位</td>
                  <td></td>
              </tr>
          </thead>
          <tbody>
              <tr>
                  <td height="30" align="center">
                      <input type="text" name="NO" size="2" value="1" />
                  </td>
                  <td align="center">
                      <input type="text" name="start_end_time" />
                  </td>
                  <td align="center">
                      <input type="text" name="unit_department" />
                  </td>
                  <td align="center">
                      <input type="text" name="post" />
                  </td>
                  <td>
                      <input type="button" id="Button2" onclick="deltr(this)" value="删行" />
                  </td>
              </tr>
          </tbody>
      </table>
  </div>

js代码:

$(function () {
           var show_count = 20;   //要显示的条数
           var count = 1;    //递增的开始值,这里是你的ID
           $("#btn_addtr").click(function () {
 
               var length = $("#dynamicTable tbody tr").length;
               //alert(length);
               if (length < show_count)    //点击时候,如果当前的数字小于递增结束的条件
               {
                   $("#tab11 tbody tr").clone().appendTo("#dynamicTable tbody");   //在表格后面添加一行
                   changeIndex();//更新行号
               }
           });
 
 
       });
       function changeIndex() {
           var i = 1;
           $("#dynamicTable tbody tr").each(function () { //循环tab tbody下的tr
               $(this).find("input[name='NO']").val(i++);//更新行号
           });
       }
 
       function deltr(opp) {
           var length = $("#dynamicTable tbody tr").length;
           //alert(length);
           if (length <= 1) {
               alert("至少保留一行");
           } else {
               $(opp).parent().parent().remove();//移除当前行
               changeIndex();
           }
       }

via:http://www.w2bc.com/article/jquery-add-row-form

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

  • jQuery搜索框输入文字下拉揭示菜单

    jQuery搜索框输入文字下拉提示菜单 jQuery搜索框输入文字下拉提示菜单 原文地址: http://www.jq22.com/jquery-info6193 ...

  • 7个替开发者准备的有用的jQuery技巧

    7个为开发者准备的有用的jQuery技巧 一、在新窗口打开链接 用下面的代码,你点击链接即可在新窗口打开: $(document).ready(fu...

  • jQuery获取呼应Input例子

    jQuery获取相应Input例子 页面上有许多input框,使用的是EasyUI样式,中间还参杂着各种其他无id的Input框,如下: <input class=...

  • webpack 引出jquery和第三方jquery插件

    webpack 引入jquery和第三方jquery插件 1、引入jquery jQuery 直接在 html 中引入,然后在 webpack 中把它配置为全局即可。 index....

  • JQuery的开发与使用经验

    JQuery的开发与使用心得 关于jQuery的 入门使用jQuery可以很容易或具有挑战性的,这取决于你如何使用JavaScript,HTML,CSS进行开发和...

  • 深入学习jQuery卡通片控制

    深入学习jQuery动画控制 &times; 目录 [1]动画状态 [2]停止动画 [3]动画延迟[4]全局控制 前面的话   jQuery动画可以使用fade、...

  • jquery操作table报表

    jquery操作table表格 一、数据准备 <table id="table1"> <tr><th>文章标题</th><th>文章分类</th><th>发布时间</th><th>...

  • html + css + jquery实现简略的进度条实例

    html + css + jquery实现简单的进度条实例 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-eq...

  • jquery中ajax方法的datatype的功用

    jquery中ajax方法的datatype的作用 今天在维护一个项目的时候遇见了一个小问题。但是这个问题我认为对于项目十分有帮助。...

  • jQuery菜单示范(全选,反选,取消)

    jQuery菜单示例(全选,反选,取消) 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <titl...

热门推荐: