如何清除表单数据jquery?

时间:2016-09-25 05:36:11

标签: javascript jquery html

我想在将所有输入数据提交到php文件后清除所有表单输入数据如何使用jquery函数清除此数据?

4 个答案:

答案 0 :(得分:1)

您可以收听提交事件,然后清除每个输入的值,如下所示:

$('#form').submit(function() {
  $(this)[0].reset();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form">
  <input type="text" />
  <input type="submit" />
</form>

答案 1 :(得分:0)

这应该有用......

&#13;
&#13;
[[0 0 0 0 0]
 [0 0 1 0 0]
 [1 0 0 1 0]
 [0 0 0 0 1]
 [1 0 0 0 0]]      
     |
     V
[[0 1 0 0 0]
 [0 1 1 0 0]
 [1 1 0 1 0]    
 [0 1 0 0 1]
 [1 1 0 0 0]]
     |
     V
[[0   0.2 0 0 0]
 [0   0.2 1 0 0]
 [0.5 0.2 0 1 0]   
 [0   0.2 0 0 1]
 [0.5 0.2 0 0 0]]
&#13;
$('form').on('submit', function() {
  var children = $(this).children()
  children.each(function(i, el) {
    if ($(el).attr('type') === 'checkbox') return $(el).removeAttr('checked')
    $(el).val(null)
  })
})
&#13;
&#13;
&#13;

答案 2 :(得分:0)

试试这个

$(document).ready(function(){
  $('#submit').click(function(){
    $('#my_form').find("input[type=text]").val("");
  });
});

答案 3 :(得分:-1)

document.querySelector(".name").value = "";
<form class="form">
  <input type="text" class="name"/>
  <input type="submit" value="Send" class="submit"/>
</form>

然后输入值将始终为空