2014-01-31 107 views
0

我有一個利用Jquery表單插件的表單。提交表單時,我需要清除頁面上的文本框。當這個Javascript運行時,我希望在運行php頁面之後清除Textfield。提交的Javascript清除文本字段

<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> 

這是我輸入字段:

$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post'}, function(){ 
    $('#glueField').val(''); 
}); 

回答

-1
jQuery (textFieldId/class).val (""); 
+0

我爲什麼downvoted? –

1

與嘗試線會爲你做的伎倆:

$('input').empty(); 
0

如果您使用的是#glue投入那麼,你的Ajax調用後,補充一點:

<input type="text" id="glueField" class="form-control" name="word" placeholder="Press enter to glue a word" autocomplete="off" autofocus> 
-1
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post', success: $("#glueField").val(''))}) 

你可以這樣做。成功時在相應的字段中設置一個空字符串。

+1

請修復您的代碼。 – hsz

+0

修好了。是否錯過了逗號? –

+0

在$(「#glueField」)後面加上'''' – hsz

2

我會從jQuery Form插件中使用這個方法,它可以清除您的ajax表單中的所有文本輸入,密碼輸入等。就像這樣:

$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post'}, function() { 
    // Callback for when post is completed 
    $('#glue').clearForm(); 
});  

更多信息here

+0

不幸的是,這並沒有清除輸入字段。 –

+0

+1使用相同的插件 –

+0

謝謝@ user2310289。你也可以用$('#glue')[0] .reset();來嘗試本地重置值。 –

0

我固定它自己。 jQuery表單插件有一個這樣做的方法。我只是改變了我的jQuery行這樣的:

$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post', clearForm: 'true'}, function() { 

添加:

clearForm: 'true'