提交时的Javascript明文字段
我有一个使用Jquery表单插件的表单。提交表单时,我需要清除页面上的文本字段。当这个Javascript运行时,我希望它在运行php页面后清除Textfield提交时的Javascript明文字段,javascript,html,Javascript,Html,我有一个使用Jquery表单插件的表单。提交表单时,我需要清除页面上的文本字段。当这个Javascript运行时,我希望它在运行php页面后清除Textfield <script> // wait for the DOM to be loaded $(document).ready(function() { // bind 'myForm' and provide a simple callback function $("#g
<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>
//等待加载DOM
$(文档).ready(函数(){
//绑定“myForm”并提供一个简单的回调函数
$(“#glue”).ajaxForm({url:'scripts/glue.php',键入:'post'})
});
这是我的输入字段:
<input type="text" id="glueField" class="form-control" name="word" placeholder="Press enter to glue a word" autocomplete="off" autofocus>
试试:
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post'}, function(){
$('#glueField').val('');
});
如果您在该
#glue
中使用输入,那么在ajax调用之后,添加这一行就可以了:
$('input').empty();
你可以这样做。成功时,为相应字段设置空字符串 我将使用jQuery表单插件中的这个方法,它清除ajax表单中的所有文本输入、密码输入等。像这样:
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post'}, function() {
// Callback for when post is completed
$('#glue').clearForm();
});
更多信息我自己修好了。jQuery表单插件有一种方法可以做到这一点。我只是将jquery行更改为:
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post', clearForm: 'true'}, function() {
添加:
clearForm: 'true'
请修改你的代码,修改好了。缺少一个逗号,对吗?在
$(“#glueField”)
Hm之后有额外的”
。这使得表单无法使用,现在它将重定向到操作页面,而不是使用ajax。但不知道为什么。不幸的是,这没有清除输入字段。+1用于使用相同的pluginThanks@user2310289。您还可以尝试使用$('#glue')[0]以本机方式重置该值$(#glue')[0]。重置();也什么也没做:/
$("#glue").ajaxForm({url: 'scripts/glue.php', type: 'post', clearForm: 'true'}, function() {
clearForm: 'true'