drz73366 2014-06-17 15:16
浏览 14
已采纳

当用户再次尝试输入用户名时,如何删除“您已被注销”

When a user logs out, they are redirected back to the login form. The login form looks at the login.php?logout=true url and if logout=true, then it displays "You've been successfully logged out." Not exactly sure how to do so otherwise as anyone can type logout=true and see that message.

How can I remove that text once the user tries to enter their username/password again?

login.php looks something like this:

<form method="post" action="login.php">

  <fieldset>

  <?php if ($disp_msg) { ?>
  <p><?php print($disp_msg); ?></p>
  <?php } ?>

  <p><input type="text" name="username" placeholder="username"></p>
  <p><input type="password" name="password" placeholder="password"></p>
  <p><input type="submit" value="Login"></p>

  </fieldset>

</form>

I'd assume I'd have to use JavaScript, although unfamiliar with it. Most likely would use onFocus or onClick in each input type field that somehow clears the output of $disp_msg

  • 写回答

1条回答 默认 最新

  • doujuncuo9339 2014-06-17 15:51
    关注

    I added two IDs. One is for your display message and other one is for your input box.

    <?php if ($disp_msg) { ?>
    <p id="msg"><?php print($disp_msg); ?></p>
    <?php } ?>
    
    <p><input type="text" name="username" placeholder="username" id="username"></p>
    <!-- other input fields -->
    </fieldset>
    </form>
    
    <!-- jQuery Code -->
    <script>
    $('#username').keypress(function(e) {
       $('#msg').empty();
    });
    </script>
    

    DEMO

    ##################################################################

    <!-- without jquery -->
    <!-- Add attribute onKeyPress in username input field. -->
    <input type="text" id="username" onKeyPress="fun()"/>
    <!-- and add this just before you </head>. Remove previous jquery code-->
    <script>
        function fun()
            {
                document.getElementById('msg').innerHTML="";
            }
    </script>
    

    DEMO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?