我用JS写了个可以增加和删除行的动态表格,当填写后要提交到一个JSP2页面,并在JSP2中显示表格的内容,哪位大侠帮忙一下,在线等!!!

解决方案 »

  1.   

    <script language="javascript" type="">
    allCount=1
    function addline()
    {
    newRow=table.insertRow(table.rows.length-1);
    newRow.ln=allCount;
    newRow.id=allCount;
    c1=newRow.insertCell(0);
    c1.bgColor="#FFFFFF";
    c1.innerHTML="<div align=center><input type=text id=room"+allCount+"name=room"+allCount+">"+allCount+"</div>";
    c2=newRow.insertCell(1);
    c2.bgColor="#FFFFFF";
    c2.innerHTML="<div align=center><input name=p"+allCount+"type=text id=p"+allCount+">"+allCount+"</div>";
    c3=newRow.insertCell(2);
    c3.bgColor="#FFFFFF";
    c3.innerHTML="<div align=center><input name=price"+allCount+"type=text id=price"+allCount+">"+allCount+"</div>";
    c4=newRow.insertCell(3);
    c4.bgColor="#FFFFFF";
    c4.innerHTML="<input type=radio name=hasb"+allCount+" value=1 />有<input name=hasb"+allCount+" type=radio value=0 checked />无";
    c5=newRow.insertCell(4);
    c5.bgColor="#FFFFFF";
    c5.innerHTML="<div align=center><input type=checkbox name=checkbox"+allCount+" value=1></div>";
    c6=newRow.insertCell(5);
    c6.bgColor="#FFFFFF";
    c6.align="CENTER";
    c6.id="line"+allCount;
    c6.innerHTML="<input type=button value=删除 onclick=delline(line"+allCount+")>";
    c7=newRow.insertCell(6);
    c7.bgColor="#FFFFFF";
    c7.align="CENTER";
    c7.innerHTML="<input type=button value=插入 onclick=insertline(line"+allCount+")>";
    allCount++
    }...............................
      

  2.   

    噢,CSDN的高手们。你们在哪里啊?????????????
      

  3.   

    你只把你的js给贴出来了
    没有jsp的代码吗?
    这样传值应该不难啊
    QQ:24699227
      

  4.   

    weky(weky) 您好,以下是JSP1的代码:如何传值到JSP2?谢谢<%@ page contentType="text/html; charset=GBK" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
    <html>
    <head>
    <title>
    jsp1
    </title>
    </head>
    <script language="javascript" type="">
    allCount=1
    function addline()
    {
    newRow=table.insertRow(table.rows.length-1);
    newRow.ln=allCount;
    newRow.id=allCount;
    c1=newRow.insertCell(0);
    c1.bgColor="#FFFFFF";
    c1.innerHTML="<div align=center><input type=text id=room"+allCount+"name=room"+allCount+">"+allCount+"</div>";
    c2=newRow.insertCell(1);
    c2.bgColor="#FFFFFF";
    c2.innerHTML="<div align=center><input name=p"+allCount+"type=text id=p"+allCount+">"+allCount+"</div>";
    c3=newRow.insertCell(2);
    c3.bgColor="#FFFFFF";
    c3.innerHTML="<div align=center><input name=price"+allCount+"type=text id=price"+allCount+">"+allCount+"</div>";
    c4=newRow.insertCell(3);
    c4.bgColor="#FFFFFF";
    c4.innerHTML="<input type=radio name=hasb"+allCount+" value=1 />有<input name=hasb"+allCount+" type=radio value=0 checked />无";
    c5=newRow.insertCell(4);
    c5.bgColor="#FFFFFF";
    c5.innerHTML="<div align=center><input type=checkbox name=checkbox"+allCount+" value=1></div>";
    c6=newRow.insertCell(5);
    c6.bgColor="#FFFFFF";
    c6.align="CENTER";
    c6.id="line"+allCount;
    c6.innerHTML="<input type=button value=删除 onclick=delline(line"+allCount+")>";
    c7=newRow.insertCell(6);
    c7.bgColor="#FFFFFF";
    c7.align="CENTER";
    c7.innerHTML="<input type=button value=插入 onclick=insertline(line"+allCount+")>";allCount++
    }
    function insertline(lineid)
    {
    for(i=0;i<table.rows.length;i++)
    {
    if(table.rows[i].cells[5].id==lineid.id)
    {
    newRow=table.insertRow(i);
    newRow.ln=allCount;
    newRow.id=allCount;
    c1=newRow.insertCell(0);
    c1.bgColor="#FFFFFF";
    c1.innerHTML="<div align=center><input type=text id=room"+allCount+"name=room"+allCount+"></div>";
    c2=newRow.insertCell(1);
    c2.bgColor="#FFFFFF";
    c2.innerHTML="<div align=center><input name=p"+allCount+" type=text id=p"+allCount+"></div>";
    c3=newRow.insertCell(2);
    c3.bgColor="#FFFFFF";
    c3.innerHTML="<div align=center><input name=price"+allCount+"type=text id=price"+allCount+"></div>";
    c4=newRow.insertCell(3);
    c4.bgColor="#FFFFFF";
    c4.innerHTML="<input type=radio name=hasb"+allCount+" value=1 />有<input name=hasb"+allCount+" type=radio value=0 checked />无";
    c5=newRow.insertCell(4);
    c5.bgColor="#FFFFFF";
    c5.innerHTML="<div align=center><input type=checkbox name=checkbox"+allCount+" value=1></div>";
    c6=newRow.insertCell(5);
    c6.bgColor="#FFFFFF";
    c6.align="CENTER";
    c6.id="line"+allCount;
    c6.innerHTML="<input type=button value=删除 onclick=delline(line"+allCount+")>";
    c7=newRow.insertCell(6);
    c7.bgColor="#FFFFFF";
    c7.align="CENTER";
    c7.innerHTML="<input type=button value=插入 onclick=insertline(line"+allCount+")>";
    allCount++return;
    }
    }
    }
    function delline(lineid)
    {
    for(i=0;i<table.rows.length;i++)
    {
    for(j=0;j<table.rows[i].cells.length;j++)
    {
    if(table.rows[i].cells[j].id==lineid.id)
    {
    table.deleteRow(i);
    return;
    }
    }
    }
    }</script>
    <body>
    <form id="form1" name="form1" method="post" action="jsp2.jsp"><table width="772" border="1" align="center" cellspacing="0" id="table" >
    <tr>
                  <td width="23%"><div align="center">房型</div></td>
                  <td width="23%"><p align="center">门市价格</p>              </td>
                  <td width="23%"><div align="center">本站价格</div></td>
                  <td width="13%"><div align="center">早餐</div></td>
                  <td width="7%"><div align="center">促销</div></td>
                  <td bordercolor="#FFFFFF" >&nbsp;</td>
                  <td bordercolor="#FFFFFF">&nbsp;</td>
    </tr>
                <tr>
              <td colspan="7"><input type="button" name="Submit3" value="增加行" onclick="addline()" />
                 <input type="submit" name="Submit" value="提交" />   </td>
              </tr>
    </table>
    </form>
    </html>