javascript 实现动态增加table的行数

<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<head>
<title>command</title>
<script type="text/javascript">

function addLines(rawId, selectId, key){
   //alert(rawId + "  " + selectId);
   var rawIndex = document.getElementById(rawId).rowIndex;
   var varSelect = document.getElementById(selectId);
   var rawNum = varSelect.options.value;
   //alert("rawIndex=" + rawIndex + "; rawNum=" + rawNum);

   var table = document.getElementById("id_requestTable");

   for(var i = 0; i < rawNum; i++)
   {
       var tr = table.insertRow(rawIndex+1);
       var td1 = tr.insertCell(0);
       var td2 = tr.insertCell(1);

       td1.innerHTML = key + ": ";
       td2.innerHTML = "<input  name=\'" + key + "\' size=\'50\' >";
   }
}
</script>
</head>
<body>
<div align="center">
Input the value in box<p>
<form method="POST" action="url">
<table border="1" id="id_requestTable">
   <tr><td align="right">loginAccountType:</td><td><input  name="loginAccountType" size="50" ></td></tr>
   <tr><td align="right">port:</td><td><input  name="port" size="50" ></td></tr>
   <tr><td align="right">cmdType:</td><td><input  name="cmdType" size="50" ></td></tr>
   <tr id="id_key"><td>key num:&nbsp;&nbsp;
           <select id="id_key_select">
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
           </select>
       </td>
       <td><input type="button" 'key');" value="submit"></td>
   </tr>
   <tr><td align="right">GameName:</td><td><input  name="GameName" size="50" ></td></tr>
   <tr id="id_key2"><td>key2 num:&nbsp;&nbsp;
           <select id="id_key2_select">
               <option value="1">1</option>
               <option value="2">2</option>
               <option value="3">3</option>
           </select>
       </td>
       <td><input type="button" 'key2');" value="submit"></td>
   </tr>
   <tr><td align="right">GameAccount:</td><td><input  name="GameAccount" size="50" ></td></tr>
</table>
<input type="submit" value="command"/>
</form>
</div>
<div align="center">

</div>
</body>
</html>

你可能感兴趣的:(增加行数)