jQuery隐藏表单提交? [英] jQuery hide form on submit?

查看:135
本文介绍了jQuery隐藏表单提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户可以注册的表单设置,并在提交时运行一个验证用户的PHP脚本,一旦完成,它会回显jQuery快速隐藏的消息框,然后在1第二。我现在想要做的就是能够隐藏提交的表单,我认为这可以做到这一点:

  $ (document).ready(function(){
$('div.mainsuccess,div.mainerror')。hide(0).fadeIn(1000);
$('form.register')。 submit(function(){
$(this).hide(1000);
});
});

其中 div.mainsuccess 是成功消息,并且 form.register 是表格(带有一个寄存器类)。现在第一行起作用了,它告诉我脚本正在被调用,但表单并没有被隐藏。我在这里做了一些愚蠢的事情,但我弄不清楚是什么?



我试着通过jQuery API文档来查看 submit( ),但我不明白说什么。谢谢。

解决方案

我认为它可能不起作用的原因是因为表单提交数据并等待页面刷新...这意味着,它会停止所有的JavaScript的东西因为它是毫无意义的...我可能是错的,但嘿,你的隐藏将需要1秒隐藏,但你的网页可以更快地刷新。


$ b $ (

  $(document).ready(function(){
$ ;
$('form.register')。submit(function(e){
e.preventDefault(); //将停止被引用的表单...
$(this) .hide(1000);
//在这里做ajax ...
返回false;
});
});

更新

这里是一个教程列表

http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html



http://www.devirtuoso.com/2009/07/beginners-guide-to-using-ajax-with-jquery/



< a href =http://www.sitepoint.com/ajax-jquery/ =nofollow> http://www.sitepoint.com/ajax-jquery/



视频....
http:// www。 youtube.com/watch?v=0CMTQtnZ0G0


I have a form setup where a user can register, and on submittal, a PHP script runs which validates the user, and once that is done, it echoes a messagebox which jQuery quickly hides and then fades in over the course of 1 second. What I now want to do is to be able to hide that form on submittal, and I thought this might do it:

$(document).ready(function() {
    $('div.mainsuccess,div.mainerror').hide(0).fadeIn(1000);
    $('form.register').submit(function() {
        $(this).hide(1000);
    });
});

Where div.mainsuccess is the success message, and form.register is the form (with a class of register). Now the first line works, which tells me the script is being called, but the form is not being hidden at all. I'm doing something stupid here, but I cannot figure out what?

I've tried to look through the jQuery API documentation for submit(), but I cannot understand what is being said. Thanks.

解决方案

I think the reason it may not work is because the form is submitting it's data and waiting for page to refresh... which means, it will stop all of it's javascript stuff coz it's pointless ... I could be wrong but hey, your hide would take 1 second to hide but your page could reload quicker.

$(document).ready(function() {
    $('div.mainsuccess,div.mainerror').hide(0).fadeIn(1000);
    $('form.register').submit(function(e) {
        e.preventDefault();// will stop the form being submited...
        $(this).hide(1000);
        // do ajax here...
        return false;
    });
});

Updated

here is a list of tutorials

http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html

http://www.devirtuoso.com/2009/07/beginners-guide-to-using-ajax-with-jquery/

http://www.sitepoint.com/ajax-jquery/

Videos .... http://www.youtube.com/watch?v=0CMTQtnZ0G0

这篇关于jQuery隐藏表单提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆