所以我想看看像stackoverflow一样的消息在顶部.
现在我已经配置了所有,但是我遇到了一个问题..消息只显示第一次,第二次没有显示.
我知道为什么,关于每个id的东西必须是唯一的或div中的东西..然后我用rand(1,300); (PHP)它仍然无法正常工作.
这是我的代码:
function checkSession(){
$.ajax({url: "session.php", success: function(data){
if( data == 1){
var postFilen = 'msg.php';
$.post(postFilen, function(data){
$(".msg").html(data).find(".message2").fadeIn("slow")
setTimeout(function(checkSession) {
$('.msg').fadeOut('slow');
}, 10000);
});
}else{
$('.message2').hide();
}
}});
// setInterval('checkSession()',1000);
}
index.php文件:
msg.php:
CloseNotice2() – (以防万一你想看到它):
function closeNotice2() {
$(".message2").fadeOut("slow");
}
session.php文件:
if(isset($_SESSION['user_message'])) {
echo 1;
}
CSS:
.message2 {
position: absolute;
top: 0;
left: 0;
z-index: 105; /* Anything higher than 1 will do */
background-color: #034678;
font-family: Arial,Helvetica,sans-serif;
font-size: 100%;
text-align: center;
font-weight: bold;
border-bottom: 2px solid #FFF;
height: 26 px;
width: 100%;
}
.message2 span {
text-align: center;
width: 95%;
float:left;
}
我想就是这样.希望你能帮助我.