如何使用java脚本隐藏文本并通过php显示另一个文本和整个java脚本代码触发器?

问题描述:

$_SESSION['MSG']="Incorrect email id and password" is in red color.

After 5 sec it will hide and after that I want to show Try again later in yellow color at same place after 5 sec. $_SESSION['try']="Try again later" but it will not hide until page is not reload or refresh:

<?php
session_start();
if(isset($_SESSION['MSG'])){
echo '<div  id="incorrect">' . $_SESSION['MSG'] .  '</div><script 
type="text/javascript">  
function showIt() {  
document.getElementById("incorrect").style.visibility = "hidden";  
}  
setTimeout("showIt()", 5000); 
</script>';
}
unset ($_SESSION['MSG']); 
session_destroy ();
?>

Try this

if(isset($_SESSION['MSG'])){
    echo '<div id="incorrect">'.$_SESSION['MSG'].'</div><script type="text/javascript">
    document.getElementById("incorrect").style.cssText = "background: red";
    function showIt() {
        document.getElementById("incorrect").style.visibility = "hidden";  
    }
    setTimeout("showIt()", 5000);
    function showIt() {
        document.getElementById("incorrect").style.cssText = "background: yellow";
        document.getElementById("incorrect").style.visibility = "visible";
        document.getElementById("incorrect").innerHTML = "'.$_SESSION["try"].'";
    }
    </script>';
}

You use the innerHTML to change the message within the <div></div>.