Home  >  Article  >  Web Front-end  >  Operation examples of copying rows and deleting rows in js_javascript skills

Operation examples of copying rows and deleting rows in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:31:28964browse
复制代码 代码如下:

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);
                });
                });
            });
  });
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn