This question already has answers here:
Resetting a multi-stage form with jQuery
(30个答案)
2年前关闭。
您能帮我写我的表格吗?我将在关闭有关发送消息的模式窗口后尝试实现重置表单,但无法正常工作!为什么?我正在使用Bootstrap 3。
(30个答案)
2年前关闭。
您能帮我写我的表格吗?我将在关闭有关发送消息的模式窗口后尝试实现重置表单,但无法正常工作!为什么?我正在使用Bootstrap 3。
<form id='send-form' action="#" method="post" target="iframe1">
<div class="input-field">
<input type="text" name="name" class="form-control" placeholder="name">
</div>
<div class="input-field">
<input type="email" name="email" class="form-control" placeholder="e-mail...">
</div>
<div class="input-field">
<input type="text" name="subject" class="form-control" placeholder="Тема...">
</div>
<div class="input-field">
<textarea name="message" class="form-control" placeholder="message"></textarea>
</div>
<div class="input-field">
<input type="checkbox" checked autocomplete="on" name="law">check</input>
</div>
<button type="submit" id="submit" class="btn btn-blue btn-effect" data-toggle="modal"
data-target="#modal-send">send</button>
</form>
<div class="modal" id="modal-send">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button id='reset-but' class="close" type="button" data-dismiss="modal">
<i class="fa fa-close fa-2x"></i></button>
<script>
$(index.html).ready(function(){
$('#reset-but').click(function () {
$('#send-form')[0].reset();
});});
</script>
<h4 class="modal-title">Сообщение отправлено<br><br></h4>
</div>
</div>
</div>
</div>
最佳答案
只需删除$(index.html).ready(function(){}
,它将起作用
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id='send-form' action="#" method="post" target="iframe1">
<div class="input-field">
<input type="text" name="name" class="form-control" placeholder="name">
</div>
<div class="input-field">
<input type="email" name="email" class="form-control" placeholder="e-mail...">
</div>
<div class="input-field">
<input type="text" name="subject" class="form-control" placeholder="Тема...">
</div>
<div class="input-field">
<textarea name="message" class="form-control" placeholder="message"></textarea>
</div>
<div class="input-field">
<input type="checkbox" checked autocomplete="on" name="law">check</input>
</div>
<button type="submit" id="submit" class="btn btn-blue btn-effect" data-toggle="modal" data-target="#modal-send">send</button>
</form>
<button id='reset-but' type="button" data-dismiss="modal">
<i class="fa fa-close fa-2x"></i></button>
<script>
$('#reset-but').click(function () {
$('#send-form')[0].reset();
});
</script>
<h4 class="modal-title">Сообщение отправлено<br><br></h4>
关于javascript - 为什么我的post表单不重置? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46601707/