dongmaopan5738 2013-03-18 19:54
浏览 25
已采纳

在PHP代码之前执行jQuery代码和动画

Hi i have been adding some animations to my website like on the login page etc

however I first found that the Animation executes but not the PHP code and when i get the PHP code to execute then the Animation doesnt work... PHP code is more important however it seems even if i use the form.submit() function in jquery the PHP code never triggers. i know this as i tried alternate methods and it works without the jQuery.

i am using 1.9.0 and here is the jQuery code

jQuery('#loginform button').click(function()
        {
            if(!jQuery.browser.msie) 
            {
                if(jQuery('#username').val() == '' || jQuery('#password').val() == '') 
                {
                    if(jQuery('#username').val() == '') jQuery('#username').addClass('error'); else jQuery('#username').removeClass('error');
                    if(jQuery('#password').val() == '') jQuery('#password').addClass('error'); else jQuery('#password').removeClass('error');
                    jQuery('.loginwrap').addClass('animate0 wobble').bind(anievent,function()
                    {
                        jQuery(this).removeClass('animate0 wobble');
                    });
                } 
                else 
                {
                    jQuery('.loginwrapper').addClass('animate0 fadeOut').bind(anievent,function()
                    {
                        $.post(username, {username});
                        $.post(password, {password});
                        jQuery('#loginform').submit();
                    });
                }
                return false;
            }
        });

as you can see, originally i got the code to post from the jquery however the animation does not run no matter what i tried.

can anyone tell me why... or what way am i supposed to make it that the animation happens then the PHP???

  • 写回答

1条回答 默认 最新

  • duanao3204 2013-03-18 21:41
    关注

    Do you have the above JS wrapped such that it waits to execute until after the document has finished loaded? If you don't, what may be happening is that the javascript is trying to act on elements that have not yet been rendered. So, perhaps #loginform button does not yet exist when it is attempting to bind to that element.

    Wrap your JS in this:

    jQuery(function(){
        // All JS that executes on load here.
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题