<!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>无标题文档</title>
<script   type="text/javascript">
var   count   =   0;
function   Add(num){      count+= 1;      var   File1   =   document.getElementById("file1");
      var   div   =   document.createElement("div");
   div.style.position = "relative"; 
      div.style.zIndex = "9999"; 
      div.style.width = "560px"; 
      div.style.height = "10px"; 
  //newDiv.style.left = (parseInt(document.body.scrollWidth) - 300) / 2 + "px"; // 屏幕居中 
      div.style.background = "#EFEFEF"; 
      div.style.border = "1px solid #860001"; 
      div.style.padding = "10px";
   div.style.margin = "25px";
      var   countTxt   =   document.createTextNode("章节"+count);
      var   inputTxt   =   document.createElement("input");
      inputTxt.type   =   "text";
      inputTxt.value   =   document.getElementById(num).value;
      inputTxt.name   =   "txt"+count;
      var   inputTxta   =   document.createElement("input");
      inputTxta.type   =   "text";
      inputTxta.value   =   document.getElementById("a"+num).value;
      inputTxta.name   =   "txt"+count;
      var   inputTxtaa   =   document.createElement("input");
      inputTxtaa.type   =   "text";
      inputTxtaa.value   =   document.getElementById("aa"+num).value;
      inputTxtaa.name   =   "txt"+count;      var   btn   =   document.createElement("input");
      btn.type   =   "button";
      btn.value   =   "删除";
      btn.onclick=function()
      {
        this.parentNode.parentNode.removeChild(this.parentNode);        var n = File1.getElementsByTagName("div");
        for(var k=0; k<n.length; k++)
        {
            n[k].firstChild.nodeValue = "章节"+(k+1);
        }
        count -= 1;
      }      div.appendChild(countTxt);
      div.appendChild(inputTxt);
      div.appendChild(inputTxta);
      div.appendChild(inputTxtaa);      div.appendChild(btn);
      File1.appendChild(div);
}
</script>
<body><div   id="file1"> </div>
<form name="addChapter" action="">
<input   name="CourseID"   id="1"   value="CourseID"   type="hidden"  />
<input   name="ChapterID"   type="hidden"   id="a1"   value="ChapterID"/>
<input   name="ChapterName"   type="hidden"   id="aa1"   value=" ChapterName" />
<input   name="xiyaonamebutton"  value="增加章节"   type="button"   onclick="Add(1);"  style="margin-left:23px;" />
<input name="submit"  value="submit"  type="submit"  style="width:75px;"/>
</form>
</body>
</html>

解决方案 »

  1.   

    先在前台js做下处理,将获得的五行值保存到form中<input type="hidden" name="aa" value="第一行的值">....<input type="hidden" name="ff" value="第五行的值">
    最后将此表单提交,进入action....
      

  2.   

    1.input中的name应该是一个变量吧,这样子后台才能接受所有的数据。id应该也保持一个变量,这样方面JS来对DOM进行操作。
    2.增加一个hidden类型的参数来控制你增加了多少行,每增加一行该变量+1.例如第一行的文本框就应该是
    <input type="text" name="user1" id="user1" value="">
    <input type="hidden" name="arg" id="arg" value="1">不过需要注意一点就是,假设在删除时你删除了中间的一行,那么所有的name和id都需要重新赋值~
      

  3.   

    不明白,对javascript代码不太懂,哪位大侠能帮小弟改一下代码再贴出来,不胜感激~,在线等。。
      

  4.   

    这东西完全是JS控制的,你对JS不太懂的话,即便给你JS代码你也不会啊~~~
      

  5.   


    <!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>无标题文档</title>
    <script type="text/javascript">
    var count = 0;
    function Add(num){   count+= 1;   var File1 = document.getElementById("file1");
       var div = document.createElement("div");
       div.style.position = "relative";  
       div.style.zIndex = "9999";  
       div.style.width = "560px";  
       div.style.height = "10px";  
       //newDiv.style.left = (parseInt(document.body.scrollWidth) - 300) / 2 + "px"; // 屏幕居中  
       div.style.background = "#EFEFEF";  
       div.style.border = "1px solid #860001";  
       div.style.padding = "10px";
       div.style.margin = "25px";
       var countTxt = document.createTextNode("章节"+count);
       var inputTxt = document.createElement("input");
       inputTxt.type = "text";
       inputTxt.value = document.getElementById(num).value;
       inputTxt.name = "txt"+count;
       inputTxt.id = "CourseID"+count;
      
       var inputTxta = document.createElement("input");
       inputTxta.type = "text";
       inputTxta.value = document.getElementById("a"+num).value;
       inputTxta.name = "txt"+count;
       inputTxta.id = "ChapterID"+count;
      
      var inputTxtaa = document.createElement("input");
       inputTxtaa.type = "text";
       inputTxtaa.value = document.getElementById("aa"+num).value;
       inputTxtaa.name = "txt"+count;
       inputTxtaa.id = "ChapterName"+count;

       var btn = document.createElement("input");
       btn.type = "button";
       btn.value = "删除";
       btn.onclick=function(){
       this.parentNode.parentNode.removeChild(this.parentNode);    var n = File1.getElementsByTagName("div");
       for(var k=0; k<n.length; k++){
       n[k].firstChild.nodeValue = "章节"+(k+1);
       }
       count -= 1;
       }   div.appendChild(countTxt);
       div.appendChild(inputTxt);
       div.appendChild(inputTxta);
       div.appendChild(inputTxtaa); div.appendChild(btn);
       File1.appendChild(div);
    } function getValue(){
    if(count){
    alert("请增加章节");
    return false;
    }
    document.getElementById("hidCount").value = count;
    return true;
    }

    </script>
    </head>
    <body>
    <div id="file1"></div>
    <form name="addChapter" action="" onSubmit="return getValue();">
    <input type="hidden" id="hidCount" value="0" />
    <input name="CourseID" id="1" value="CourseID" type="hidden" />
    <input name="ChapterID" type="hidden" id="a1" value="ChapterID" />
    <input name="ChapterName" type="hidden" id="aa1" value=" ChapterName" />
    <input name="xiyaonamebutton" value="增加章节" type="button" onclick="Add(1);" style="margin-left: 23px;" />
    <input name="submit" value="submit" type="submit"style="width: 75px;" />
    </form>
    </body>
    </html>
    每次增加章节的时候,要给增加的标签赋值id的值,这里一定要根据count来定,否定会重复。
    form表单中添加了一个隐藏表单域。
    提交action后,在Action里获取隐藏表单域hidCount的值,根据它的值来循环取出页面上标签的值。int count = request.getParamter("hidCount");
    List info = new ArrayList();
    for(int i=0; i<count; i++){
      info.add(request.getParamter("CourseID"+i);
      info.add(request.getParamter("ChapterID"+i);
      info.add(request.getParamter("ChapterName"+i);
    }java代码我是直接在csdn这个回复框里敲的,比如有什么类型转换之类的错误,lz自己再改改。
    count值代表前台用户添加了几行章节,然后循环分别取出每个文本框的值就行。
      

  6.   

    哎,这个csdn,我还特意把我新加的代码用红色字体标注了,结果发上去竟然是源码~~~楼主Ctrl+F一下“[color=#FF0000]”,这些代码都是我新添加的