0

我有一个 php 类,用于在操作(发布表单/更新页面)当前刷新页面和 psts 1 或 0 之后显示成功消息或失败消息,然后是以下代码 - - 我怎样才能让它弹出起来并自动关闭...就像绿色的勾号或十字...假设需要使用 jquery - - 完全迷失在这里所以欢迎任何建议...谢谢

   <?
    $response = $_GET['response'];
    if ($response == '0') {
    echo"
    <div class=\"error message\">
                 <h5>FYI, something just happened!</h5>
                 <p>This is just an info notification message.</p>
    </div>
    ";
    }
    if ($response == '1') {
    echo"
    <div class=\"success message\">
                 <h5>FYI, something just happened!</h5>
                 <p>This is just an info notification message.</p> 
    </div>
    ";
    }
    ?>
4

2 回答 2

1

首先尝试这个http://jsfiddle.net/tanducar/bJ6L9/1/

如果您通过 ajax 收到此弹出消息,那么...这里是代码

$(document).ready(function(){
         ... your ajax call here
         success: function(data){
            var popup= $('<div>');
            popup.append(data);
            $('body').append(popup);
            popup.css("position","absolute");
            popup.css("top", ($(window).height() - popup.height() ) / 2+ $(window).scrollTop() + "px");
            popup.css("left", ($(window).width() - popup.width() ) / 2+ $(window).scrollLeft() + "px");

            popup.fadeOut(3000);
         }
     ......

})

在 javascript 中编写您的 php 代码。

    <script>
    $(document).ready(function(){
<?php    
$response = $_GET['response'];
     if ($response == '0') { ?>
      var data = $('<div class="success message"><h5>FYI, something just happened!</h5> <p>This is just an info notification message.</p> </div>');
    <?php } 
        if ($response == '1') {?>
       var data = $('<div class=\"success message\"><h5>FYI, something just happened!</h5><p>This is just an info notification message.</p> </div>');
    </div>
    <?} ?>


     var popup= $('<div>');
     popup.append(data);
     $('body').append(popup);
     popup.css("position", "absolute");
     popup.css("top", ($(window).height() - popup.height()) / 2 + $(window).scrollTop() + "px");
     popup.css("left", ($(window).width() - popup.width()) / 2 + $(window).scrollLeft() + "px");
     popup.fadeOut(2000);
    });

    </script>
于 2012-06-05T06:45:35.527 回答
0
$(function() {
    setTimeout(function() {
        $("#message").hide('blind', {}, 500)
    }, 5000);
});

它将在 5 秒后关闭您的弹出窗口

于 2012-06-05T06:29:14.277 回答