成功或失败的弹出窗口

时间:2012-06-05 06:25:33

标签: jquery

我有一个php类,用于在操作(发布表单/更新页面)后显示suceess消息或失败消息,当前刷新页面并按下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>
    ";
    }
    ?>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

$(function() {
    setTimeout(function() {
        $("#message").hide('blind', {}, 500)
    }, 5000);
});

它会在5秒钟后关闭你的弹出窗口