gpt4 book ai didi

javascript - 如何在 Bootstrap 模式中提交提交数据?

转载 作者:行者123 更新时间:2023-11-28 17:55:38 24 4
gpt4 key购买 nike

我有一个包含两个输入的表单,用户名密码以及一个确认任务的模式。模式打开并尝试提交后,它什么也不做:

    <form action="login.php" method="POST" id="form1">

<input class="form-control" placeholder="Enter username" name="username" id="username">
<input class="form-control" placeholder="Enter password" name="password" id="password">

<input type="button" name="btn" value="Submit" id="submitBtn" data-toggle="modal" data-target="#confirm-submit" class="btn btn-default" />

</form>

<div class="modal fade" id="confirm-submit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Confirm Submit
</div>
<div class="modal-body">
is your username and password correct?
<table class="table">
<tr>
<th>username</th>
<td id="uname"></td>
</tr>
<tr>
<th>password</th>
<td id="psw"></td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a href="#" id="submit" class="btn btn-success success">Submit</a>
</div>
</div>
</div>
</div>

<script>
$('#submitBtn').click(function() {
$('#uname').text($('#username').val());
$('#psw').text($('#password').val());
});

$('#submit').click(function(){
$('#form1').submit();
});
</script>

表单数据必须使用POST方法发送到服务器。如何实现这一目标?任何答案都值得赞赏。

最佳答案

您的模态表单超出 form 范围标记 so,它不是 HTML form 的一部分因此它不会发布任何数据。HTML form element 定义了一个用于收集用户输入的表单,并且可以包含其他 HTML 元素。

此外,您还可以使用<input type="submit"><button type="submit">将数据直接提交form .

$('#submitBtn').click(function() {
$('#uname').text($('#username').val());
$('#psw').text($('#password').val());
});

$('#submit').click(function(){
$('#form1').submit();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="login.php" method="POST" id="form1">

<input class="form-control" placeholder="Enter username" name="username" id="username">
<input class="form-control" placeholder="Enter password" name="password" id="password">

<input type="button" name="btn" value="Submit" id="submitBtn" data-toggle="modal" data-target="#confirm-submit" class="btn btn-default" />

<div class="modal fade" id="confirm-submit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Confirm Submit
</div>
<div class="modal-body">
is your username and password correct?
<table class="table">
<tr>
<th>username</th>
<td id="uname"></td>
</tr>
<tr>
<th>password</th>
<td id="psw"></td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a href="#" id="submit" class="btn btn-success success">Submit</a>
</div>
</div>
</div>
</div>

</form>

关于javascript - 如何在 Bootstrap 模式中提交提交数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44524719/

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