问题描述
好吧,我尝试了所有可以找到的建议,但是提交表单和fadeOut之后,这些值仍然存在.如果有人有建议...
Ok, I've tried every suggestion that I could find, but those values are still there after submitting form and fadeOut. If anyone has a suggestion...
<script type="text/javascript">
$(document).ready(function() {
$('#form1').ajaxForm( { beforeSubmit: validate } );
function validate(formData, jqForm, options) {
var name = $('input[name=name]').fieldValue();
var email = $('input[name=email]').fieldValue();
var message = $('textarea[name=message]').fieldValue();
if (!name[0]) {
alert('Please enter a value for name');
return false;
}
if (!email[0]) {
alert('Please enter a value for email');
return false;
}
if (!message[0]) {
alert('Please enter a value for message');
return false;
}
}
var name = $('input[name=name]').val('');
var email = $('input[name=email]').val('');
var message = $('textarea[name=message]').html('');
$("#form1").ajaxForm(function(){
$("#formplic").fadeOut(1000, function() {
$(this).html("<img src='images/postauto2.png'/>").fadeIn(2000);
});
});
});
</script>
我已经添加了建议,但仍然无法正常工作.也许我没有把它们放在正确的位置...?
I've added the suggestions, but it's still not working. Maybe I am not putting them in the right place...?
推荐答案
编辑:为什么不起作用通读您的脚本.您添加的建议(我的代码)只是全局范围内的一条常规语句-当浏览器加载文件时
Edit: Why it's not workingRead through your script. The suggestion you added (my code) is just a regular statement in the global scope - When the browser loads the file it
- 设置文档准备方法
- 实现功能验证
- 执行空白设置值
- 设置ajaxForm值
- Sets the document ready method
- Realizes the function validate
- Executes the set-value-to-blank
- Sets the ajaxForm value
我假设您要在表单通过验证(并继续操作)后重设它.
I'm assuming you want to reset the form after it's been validated (and move on).
在这种情况下,您希望重置代码在完成表单后运行.那是什么时候此处:$("#form1").ajaxForm(function(){...
In that case, you want the resetting-code to run when the form is done. When is that? Here: $("#form1").ajaxForm(function(){...
其他人实际上已经为您提供了准确的代码(我相信),但是我真的认为这与您对计算机和javascript以及语言执行方式的理解有关.您实际上应该做更多的作业,并尝试遵循脚本的逻辑. alert("I'm resetting the values now!")
之类的简单调试工具会告诉您代码的执行时间(是否在正确的位置)
Someone else has actually given you the exact code (I believe) but I really think it's an issue with your understanding of computers and javascript and how languages execute. You should really do more homework and try to follow the logic of your script. Simple debugging tools such as alert("I'm resetting the values now!")
would tell you when your code is executing (whether it's in the right place or not)
在代码中的任何地方,它实际上都不会尝试清除文本.这些是一些指示,告诉浏览器重设/擦除内容.我猜您只想在正确时才清除它,以便将其添加到.ajaxForm
回调
Nowhere in your code does it actually try to clear the text. These would be some instructions to tell the browser to reset/erase the content. I'm guessing you want to clear it only when it's correct so you would add it to the .ajaxForm
callback
var name = $('input[name=name]').val(''); //inputs are like this <input value="Hi">
var email = $('input[name=email]').val('');
var message = $('textarea[name=message]').html(''); //textareas are like this <textarea>Hi</textarea>
顺便说一句,fadeOut只能使其淡出",它最终隐藏了该块(css显示:无;我猜是这样),但不会更改DOM元素/表单.
And by the way, fadeOut only makes it "fade out", it ends up hiding the block (css display: none; I'm guessing), but doesn't change the DOM element/form.
这篇关于提交表单后无法清除输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!