2013-03-22 87 views
1

所以我的代码:重定向,然后在另一个页面上运行功能?

header("Location: ".$config['site_url']."index.php#login-box"); 

这是我试图触发一个jQuery登录表单的HTML代码,如果用户没有登录:

<li><a class="log" href="#login-box"><span class="hover" style="opacity: 0;"></span></a></li> 

但是,当它运行一切确实是添加#登录框,然后结束我的网址,并不会触发#登录框href。我知道很蹩脚的尝试,但有什么想法?

这是jquery脚本,我该如何添加你提到的代码?

   $(document).ready(function() { 
$('a.login-window2').click(function() { 

      //Getting the variable's value from a link 
    var loginBox = $(this).attr('href'); 

    //Fade in the Popup 
    $(loginBox).fadeIn(300); 

    //Set the center alignment padding + border see css style 
    var popMargTop = ($(loginBox).height() + 24)/2; 
    var popMargLeft = ($(loginBox).width() + 24)/2; 

    $(loginBox).css({ 
     'margin-top' : -popMargTop, 
     'margin-left' : -popMargLeft 
    }); 

    // Add the mask to body 
    $('body').append('<div id="mask"></div>'); 
    $('#mask').fadeIn(300); 

    return false; 
}); 

// When clicking on the button close or the mask layer the popup closed 
$('a.close, #mask').live('click', function() { 
    $('#mask , .login-popup').fadeOut(300 , function() { 
    $('#mask').remove(); 
}); 
return false; 
}); 
}); 
      </script> 

回答

2

这里是一个小片段,应该做的伎俩,使用jQuery你提到:

$(function(){ 
    $("a.login-window2").click(function(){ 
     //Getting the variable's value from a link 
     var loginBox = $(this).attr("href"); 
     //Fade in the Popup 
     $(loginBox).fadeIn(300); 
     //Set the center alignment padding + border see css style 
     var popMargTop = ($(loginBox).height() + 24)/2; 
     var popMargLeft = ($(loginBox).width() + 24)/2; 
     $(loginBox).css({ 
      "margin-top" : -popMargTop, 
      "margin-left" : -popMargLeft 
     }); 
     // Add the mask to body 
     $("body").append("<div id=\"mask\"></div>"); 
     $("#mask").fadeIn(300); 
     return(false); 
    }); 
    // When clicking on the button close or the mask layer the popup closed 
    $("a.close, #mask").live("click", function(){ 
     $("#mask , .login-popup").fadeOut(300, function(){ 
      $("#mask").remove(); 
     }); 
     return(false); 
    }); 
    // Check the hash 
    var hash = $(location).attr("hash"); 
    if(hash == "#login-box") { 
     $("a.login-window2").click(); 
    } 
}); 

index.php文件将这个从if语句中运行代码。

+0

我可能已经逼近了错误的方式,我加了jQuery,我想知道如何添加该代码,它得到它的工作 – user1325578 2013-03-22 02:08:35

+0

使用脚本你必须使登录框和掩码出现,检查我的答案更新(未经测试,但它应该工作)。 – faino 2013-03-22 02:14:30

+0

我的网址末尾显示/index.php#login-box,但它仍然不会触发此代码 – user1325578 2013-03-22 02:24:57

-1

这是您的代码中的错误。

用途:name="#login-box"

代替:href="#login-box"

+1

重定向是通过'header(...)'行完成的,而不是下面的代码。 – 2013-03-22 02:08:33

相关问题