【问题标题】:Why my post-form is not reseting? [duplicate]为什么我的后表单没有重置? [复制]
【发布时间】:2017-10-06 08:40:10
【问题描述】:

您能帮我处理我的后期表单吗?在关闭带有发送消息的模式窗口后,我将尝试实现重置表单,但它不起作用!为什么?我正在使用 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>

【问题讨论】:

标签: javascript jquery html twitter-bootstrap-3


【解决方案1】:

只需删除$(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>

【讨论】:

  • 或者,就此而言,将其从 $(index.html) 编辑为 $(document)。在这个 jsfiddle 中测试:jsfiddle.net/7rkfuLws
  • 您的代码在这里确实有效,但在我的 localhost 上无效..
  • @AndreykinSergey 您可以将文件夹与您的项目一起发送吗? telegin.zhenya@gmail.com
  • @ZhenyaTelegin 是的,当然
  • @AndreykinSergey 检查邮件^^
猜你喜欢
  • 2020-01-03
  • 1970-01-01
  • 2015-12-18
  • 2022-08-17
  • 1970-01-01
  • 1970-01-01
  • 2014-04-08
相关资源
最近更新 更多