gpt4 book ai didi

javascript - 如何在没有PHP或数据库的情况下将表单数据添加到同一页面的表格中?

转载 作者:行者123 更新时间:2023-11-28 00:53:18 24 4
gpt4 key购买 nike

我有一个模态表单。我一直在试图弄清楚如果我在表单中输入数据并单击提交,它会自动显示到同一页面上的表格中。一直在尝试使用 JQuery,但它不会显示。

最佳答案

我希望这就是你要找的,试试吧:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>kkgk</title>
<script src="assets/js/jquery.js"></script>
<style>
table {
border: 1px solid black;
}
td,th {
border:1px solid black;
}
</style>
</head>

<body>

<form class="formulaire">
<input type="text" class="field1">
<input type="text" class="field2">
<input type="submit" value="press">

</form>

<table>
<tr>
<th>Nom</th>
<th>Prenom</th>
</tr>
<tr>
<td>Clegane</td>
<td>Hound</td>
</tr>
</table>

<script>
$(document).ready(function () {

$(".formulaire").submit(function (e) {
e.preventDefault()
var name = $(".field1").val()
var pronoun = $(".field2").val()

$("table").append("<tr><td>"+name+"</td><td>"+pronoun+"</td></tr>")

})
})
</script>
</body>
</html>

关于javascript - 如何在没有PHP或数据库的情况下将表单数据添加到同一页面的表格中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46090009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com