javascript中 如何将表单中输入的数据提交到表格中去?

<html>
<head>
<script type="text/javascript">
function doSubmit(){
var userName=document.getElementById("userName").value;
var userPass=document.getElementById("userPass").value;

}
</script>
</head>

<body>
<table border="1" width="500" align="center">
<thead >

<tr>
<td>账号</td><td>密码</td><td>地址</td>
</tr>

</thead>

<tbody>
<tr>
<td></td>
</tr>
</tbody>

<tfoot>

</tfoot>
</table>
<hr color="red">

<form onsubmit="return doSubmit()">
userName:<input type="text" id="userName">
<br />
userPass:<input type="password" id="userPass">
<br />
<input type="submit" value="提交">
</form>
</body>
</html>
我进行到这步就进行不下去了,不知道用什么方法可以讲userName和userPass中输入的数据传到thead表格中去,请高手来帮一下忙!
本人初学,希望尽量详细点,最好在这段代码的基础上加以完成,谢谢!

<html>
<head>
<script type="text/javascript">
function doSubmit(){
var userName=document.getElementById("userName").value;
var userPass=document.getElementById("userPass").value;
document.getElementById("user").innerHTML=":"+userName;
document.getElementById("psd").innerHTML=":"+userPass;
return false;
}
</script>
</head>

<body>
<table border="1" width="500" align="center">
<thead >

<tr>
<td>账号<span id='user'></span></td><td>密码<span id='psd'></span></td><td>地址</td>
</tr>

</thead>

<tbody>
<tr>
<td></td>
</tr>
</tbody>

<tfoot>

</tfoot>
</table>
<hr color="red">

<form onsubmit="return doSubmit()">
userName:<input type="text" id="userName">
<br />
userPass:<input type="password" id="userPass">
<br />
<input type="submit" value="提交">
</form>
</body>
</html>追问

谢谢!
如何在 中每输入一组数据,就自动创建一行新的表格,并将数据提交到该行对应的单元格内 ?这才是我的本意,嘿嘿!

追答



function doSubmit(){
var userName=document.getElementById("userName").value;
var userPass=document.getElementById("userPass").value;
row = document.getElementById("TableA").insertRow();
if(row!=null){
cell=row.insertCell();
cell.innerHTML=userName;
cell = row.insertCell();
cell.innerHTML=userPass;
cell = row.insertCell();
cell.innerHTML=" ";
}
return false;
}

账号密码地址

userName:

userPass:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-02
这个问题有多种处理方法。说一个简单的,
你可以在你要添加的表格中的最内层标签中加入id 如<td id='name1'>账号</td>
然后再JS脚本中给这个id 重新赋值,如 document.getElementById("name").value="你要显示的内容"。这样就可以了。