我有一个使用jQuery表单插件的表单。提交表格后,我需要在页面上清除文本字段。当运行此JavaScript时,我希望在运行PHP页面后清除TextField。
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post'})
});
</script>
这是我的输入字段:
<input type="text" id="glueField" class="form-control" name="word" placeholder="Press enter to glue a word" autocomplete="off" autofocus>
我将使用jQuery表单插件中的此方法,该插件清除了Ajax表单内部的所有文本输入,密码输入等。这样:
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post'}, function() {
// Callback for when post is completed
$('#glue').clearForm();
});
更多信息在这里
尝试:
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post'}, function(){
$('#glueField').val('');
});
如果您在该 #glue
中使用输入,那么,在您的ajax调用后,添加此行将为您带来技巧:
$('input').empty();
我自己修复了它。jQuery表单插件具有这样做的方法。我只是将jQuery线更改为:
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post', clearForm: 'true'}, function() {
添加:
clearForm: 'true'
jQuery (textFieldId/class).val ("");
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post', success: $("#glueField").val(''))})
您可以这样做。将一个空字符串设置为成功的各个字段。