2014-06-17 15 views
0

當用戶註銷時,它們會被重定向回登錄表單。登錄表單查看login.php?logout = true url,如果logout = true,則顯示「您已成功註銷」。不完全確定如何這樣做,否則任何人都可以輸入logout = true並查看該消息。當用戶再次嘗試輸入用戶名時,如何刪除「您已註銷」

一旦用戶嘗試再次輸入其用戶名/密碼,我該如何刪除該文本?

的login.php看起來是這樣的:

<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> 

我想我不得不使用JavaScript,雖然不熟悉它。最有可能在每個輸入類型字段中使用onFocus或onClick,以某種方式清除$ disp_msg的輸出

+1

使用javasript'onkeypress'事件。 – Prateek

+0

好的。如何清除打印後的$ disp_msg? – user3727412

+0

檢查答案。 – Prateek

回答

0

我添加了兩個ID。一個用於顯示消息,另一個用於輸入框。

<?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

+0

不適合我。 jQuery代碼是否需要下面的表單或可以在部分? – user3727412

+0

你需要添加jQuery庫。之前'' '' 然後 罩住jquery的代碼轉換成腳本標記緊跟在上面的代碼之後,並且在'' – Prateek

+0

之前我已經添加了,但仍然不起作用。 – user3727412

相關問題