這裏的東西是通過在文本框中輸入值來添加表格行。 即如果我在文本框中輸入2並單擊提交,它將添加兩個表格行。 我一直在尋找解決方案,但我現在無法找到答案。如何從輸入文本框的值中動態添加HTML表格中的表格行
<form align="center" method="GET">
<input type="text" name="users" id="user_id"><br>
<input type="submit" id="mysubmit" value="Submit" onClick="addMoreRows()">
</form>
<table id="tbl_id" style="text-align:center" align="center" valign:"top">
<thead>
<tr>
<th>Name</th>
<th>Score</th>
<th>Points</th>
<th>Total</th>
</tr>
</thead>
</table>
<script type="text/javascript">
var rowsAdd = document.getElementById('tbl_id').insertRow();
var rowsAdded;
function addMoreRows(){
rowsAdded = document.getElementById('user_id').value();
for(int x=0; x<rowsAdded; x++){
var newCell = newRow.insertCell();
newCell.innerHTML="<tr><td><input type='text' name='user_name'></td></tr>";
newCell = newRow.insertCell();
newCell.innerHTML="<tr><td><input type='text' name='score'></td></tr>";
newCell = newRow.insertCell();
newCell.innerHTML="<tr><td><input type='text' name='points'></td></tr>";
newCell = newRow.insertCell();
newCell.innerHTML="<tr><td><input type='text' name='total'></td></tr>";
}
我哪裏出錯了? 或者所有的代碼是完全錯誤的?
'的for(int x = 0'?試試'爲(VAR X = 0' – RobG 2014-11-23 12:09:37
@RobG是的,它應該是無功..謝謝..也 – myooomyoo 2014-11-23 12:20:58