我有一个表单,当我点击提交按钮时,我想要清除所有数据输入。我的下面的脚本不起作用:
<!-- 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>
答案 0 :(得分:0)
您好我认为问题在于您的表单中未包含class="myform"
。
如您所见,您正在申请reset()
班级myform。
$(".myform")[0].reset();
您也可以像id="myidform"
然后在你的jquery
中使用它 $("#myidform")[0].reset();