js如何将表单中数据添加到表格中

2024-10-12 10:50:43

1、这里用一个例子来说明耦嘀扔硇怎么添加数据。首先新建一个空白的html文件,添加表单数据:三个文本框,一个提交按钮,一个表格。<body> <form onsubmit="return submitTable()"> 账号:<input type="text" id="account"><br> 姓名:<input type="text" id="name"><br> 密码:<input type="password" id="password"><br> <input name="submit" type="button" id="submit" value="提交" onclick="return submitTable()"> </form> <hr> <table border="1" width="50%" align="center" id="table"> <tr> <th>账号</th><th>姓名</th><th>密码</th> </tr> </table></body>可以直接复制上面的代码到编辑器中测试。效果如图所示:

js如何将表单中数据添加到表格中

4、再次输入可以见到新增一条数据。

js如何将表单中数据添加到表格中
猜你喜欢