2013-07-02 74 views

回答

0

您可能需要在JavaScript函數處理函數中返回false。您也可以查看event.preventDefault。

0
Below is my code: 


<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<script language="javascript"> 
    var counter=0; 
    function addMore() 
    { 
     ++counter; 
     var string = '<div><table border="1"><tr><td><label>Name</label><input type="text" name="txtName'+counter+'"/></td></tr><tr><td><label>Age</label><input type="text" name="txtAge'+counter+'"/></td></tr></table></div>'; 
document.getElementById("content").innerHTML+=string; 
    } 
</script> 
</head> 

<body> 
<form action="display.php" method="post"> 
    <div id="content"> 
     <table> 
      <tr> 
       <td><label>Name</label><input type="text" id="txtName0" name="txtName0" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <label>Age</label><input type="text" id="txtAge0" name="txtAge0" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <input type="button" onclick="javascript:addMore()" /> 
       </td> 
      </tr> 
     </table> 
    </div> 
    <input type="submit" value="display" />`enter code here` 
    </form> 
</body> 
</html>