首页  >  文章  >  web前端  >  js中复制行和删除行的操作实例_javascript技巧

js中复制行和删除行的操作实例_javascript技巧

WBOY
WBOY原创
2016-05-16 17:31:28960浏览
复制代码 代码如下:

var validateForm = null;
  var num = 2;
  $(document).ready(function(){

   var lastCommunAddTr = $("#workDay");

   $("#add").click(function() {

         //复制一行
               var tr = $("#workDay").clone();
               tr.find("#dayMsg1").get(0).style.display="none";
                 tr.find("#remarkMsg1").get(0).style.display="none";
               tr.find("#msg1").get(0).style.display="none";
                tr.find("#day1").get(0).value="";
                tr.find("#dayMsg1").get(0).id="dayMsg"+num;
                tr.find("#day1").get(0).id="day"+num;
                tr.find("#msg1").get(0).id="msg"+num;
                tr.find("#remark1").get(0).value="春节";
               tr.find("#state1").get(0).id="state"+num;
              tr.find("#remark1").get(0).id="remark"+num;
              tr.find("#remarkMsg1").get(0).id="remarkMsg"+num;
               tr.show();
               tr.insertAfter(lastCommunAddTr);
               lastCommunAddTr = tr;
               num++;

            });

            //删除一行
            $("#workDayDel").click(function() {
                var delIndexs = new Array(0);

                $(".trWorkDay:gt(0)").each(function(i) {

                 if($(this).find("#ck").get(0).checked == true){
                  delIndexs.splice(delIndexs.length,0,i);
                     $(this).remove();
                    }
                     $(".trWorkDay").each(function() {

                 lastCommunAddTr = $(this);
                });
                });
            });
  });
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn