重定向,然后在另一个页面上运行函数


Redirecting and then run function on another page?

所以我有代码:

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> 

但是当它运行时,它所做的只是在我的url的末尾添加#login-box,而不会触发#login-box 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>

下面是一小段代码,应该可以做到这一点,使用您提到的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语句中运行代码。

这是你代码中的一个错误。

使用:name="#login-box"

代替:href="#login-box"