Javascript 清除数据表单提交按钮php

Javascript 清除数据表单提交按钮php,javascript,html,forms,Javascript,Html,Forms,我有一个表格,我想,当我点击提交按钮,所有的数据输入将被清除。我下面的脚本不起作用: <!-- language: lang-js --> jQuery(document).ready(function($) { $('.product_submit button').on('click', function(event) { event.preventDefault(); $('span.loadding').html('<i class="fa fa-

我有一个表格,我想,当我点击提交按钮,所有的数据输入将被清除。我下面的脚本不起作用:

<!-- language: lang-js -->

jQuery(document).ready(function($) {
  $('.product_submit button').on('click', function(event) {
    event.preventDefault();
    $('span.loadding').html('<i class="fa fa-spin fa-refresh" aria-hidden="true"></i>');
    var data_form = $("#form-product").serialize();
    $.ajax({
      type: 'post',
      url: location,
      data: data_form,
      success: function(resulf) {
        var errors = $(resulf).find('#alert_order').html();
        var html = $(resulf).find('#add-to-order-success').html();
        if (html) {
          $('#add-to-order-success').html(html);
          $(".myform")[0].reset();
        }
        if (errors) {
          $('#add-to-order-success').html(errors);
        }
        $('span.loadding').html('<i class="fa fa-check" aria-hidden="true"></i>');
      }
    })
  })
});

<!-- language: lang-html -->

<div class="form-add-cart">
  <form method="post" action="" id="form-product" name="myform">
    <table>
      <tbody>
        <tr>
          <td width="40%">
            <?php _e('Họ và tên:','wow'); ?>
          </td>
          <td width="60%"><input type="text" name="name_order" value="<?php echo $current_user->display_name; ?>" size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false" required></td>
        </tr>
        <tr>
          <td width="40%">
            <?php _e('Điện thoại:','wow'); ?>
          </td>
          <td width="60%"><input type="text" name="phone_order" value="" class="wpcf7-form-control wpcf7-text" aria-invalid="false" required></td>
        </tr>
        <tr>
          <td width="40%">
            <?php _e('Sản phẩm :','wow'); ?>
          </td>
          <td width="60%"><input type="text" name="product_order" value="<?php the_title();  ?>" class="wpcf7-form-control wpcf7-text" aria-invalid="false" required></td>
        </tr>
      </tbody>
    </table>
    <div class="product_submit">
      <button type="submit" class="wpcf7-form-control wpcf7-submit">
                    <?php _e('Gửi','wow'); ?>   <span class="loadding"></span>
                </button>
    </div>
    <input type="hidden" name="id_product" value="<?php echo $post->ID; ?>">
    <input type="hidden" name="add_product_to_order" value="<?php echo $post->ID; ?>">
  </form>
</div>

jQuery(文档).ready(函数($){
$('.product_submit button')。在('单击')上,函数(事件){
event.preventDefault();
$('span.loading').html(“”);
var data_form=$(“#form product”).serialize();
$.ajax({
键入:“post”,
url:位置,
数据:数据表,
成功:函数(resulf){
var errors=$(resulf).find('#警报顺序').html();
var html=$(resulf).find(“#添加到订单成功”).html();
如果(html){
$(“#添加到订单成功”).html(html);
$(“.myform”)[0].reset();
}
如果(错误){
$(“#添加到订单成功”).html(错误);
}
$('span.loading').html(“”);
}
})
})
});

您好,我认为问题在于您的表单中没有包含
class=“myform”

如您所见,您正在应用于
reset()
类myform

$(“.myform”)[0].reset()

您也可以像
id=“myidform”

然后在jquery中使用它


$(“#myidform”)[0]。重置()

“不工作”不是问题描述。使用(点击
F12
)并读取任何错误。具体问题是什么?预期结果是什么?表单发送了数据,但在单击提交时不重置数据输入。这是表单名称:(请在表单中设置一个类名称,类似于
…然后在jquery
$(“.yourclassnameform”)[0]中使用它。重置();
@Hoángah您测试过它吗?我使用:$('input[type=“text”],textarea').val(“”);这对我很有用。感谢您的支持:)