javascript - 如何使用java脚本隐藏文本并显示另一个文本和整个java脚本代码由php触发?
问题描述
$_SESSION['MSG']="Incorrect email id and password"
是红色的。
5 秒后它会隐藏,然后我想在 5 秒后在同一位置以黄色显示稍后再试一次。$_SESSION['try']="Try again later"
但它不会隐藏,直到页面没有重新加载或刷新:
<?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 ();
?>
解决方案
尝试这个
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>';
}
您使用innerHTML
来更改 中的消息<div></div>
。
推荐阅读
- php - 如何在刀片内部弹出模态表单
- excel - 查找并突出显示系列/列 VBA 中的最后一个数据点
- ckeditor - 将图像数据从 CKEditor 5 上传到 Firebase 存储会创建格式错误的图像
- swift - 为什么我使用 UNUserNotificationCenter 创建的本地通知未显示在屏幕右上角?
- java - 联合实际和预期相同,但测试失败
- python - 用Python自动创建基于两个等长列表的字典列表
- docker - 无法从 docker-compose 访问其他服务的服务
- excel - 当输入同时满足两个条件时,为什么AND语句不返回true
- java - 创建全局常量类的优雅方式
- r - 统计上一个时间段的事件数