1

I am trying to hide the login and register button once the user is registered. It doesn't work as expected as it hides the login and SIGN UP butoon, but it doesn't bring them back once logged out. Below is the PHP code.

   <div class="login"><a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">LOG IN</a></div>

   <div class="login"><a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">SIGN UP</a></div>

   $message = $_SESSION['valid_user'];
   <div class="message">
        <?php
        echo "$message";
        ?>
    </div>

Below is the jQuery code:

$(document).ready(function(){
    x = $(".message").text().length;
    if ( x >=1) {
        $(".login").hide();
    }
    else {
        $("#logout").hide();
    }
});
4

1 回答 1

2

您需要显示按钮,因为您在登录时隐藏了它们。您需要像这样更改代码。

$(document).ready(function(){ 
    x = $(".message").text().trim(); 
    if ( !!x) { 
        $(".login").hide(); 
        $("#logout").show(); 
    } 
    else { 
        $("#logout").hide(); 
        $(".login").show(); 
    } 
});
于 2013-08-11T11:50:06.877 回答