dqm7854 2014-06-26 05:35
浏览 46
已采纳

PHP和JQuery删除了正确的东西

I am making little warning/alert boxes with PHP and JQuery, and I am having a little problem. My problem is, when I click close, the box doesnt stay closed, and it doesnt close the right box. If there is more than one alert, I want the boxes to stack up, and be on top of each other, so when you close the top one, the one that was before it shows up. At the moment when you close it, the box behind the one I'm trying to close closes, and it only closes for about 3 seconds(Then the page gets refreshed by JQuery and opens it again.) So I need a way to delete the box, but I can't do that without getting the id of the box. Here is the code I'm using.

<script>

function open_box()
{

    $("#box").show();

}

$(document).ready(function()
{

    $(".close").click(function()
    {


        $("#box").fadeOut("slow");
        //$("body").load("update_box");

    });

    $("#box").dblclick(function()
    {

        $("#box").effect("highlight");

    });

});

</script>
<style>
        .AlertTitle
        {

            font-size:2em;
            text-align:center;
            position:relative;
            top:-8px;

        }

        #box
        {

            background-color:#fefefe;
            border:2px solid #5556a7;
            border-radius:10px;
            width:50%;
            height:20%;
            position:fixed;
            z-index:1000;
            left:25%;
            padding-left:25px;
            padding-top:10px;
            top:30%;
            box-shadow:0px 0px 100px 2px grey;
            overflow-x:hidden;

        }

        .close
        {

            position:absolute;
            top:-2px;
            left:-1px;
            border:2px solid #5556a7;
            border-bottom-right-radius:10px;
            border-top-left-radius:10px;
            width:15px;
            height:19px;
            padding-top:2px;
            padding-left:2px;

        }

        .close:hover
        {

            font-weight:bold;

            cursor:pointer;

        }

    </style>
<?php

require("core.php");
$id = $user->user_id();
$query = mysql_query("SELECT * FROM `warnings` WHERE `user_id` = '$id' ORDER BY `id` ASC") or die(mysql_error());
while($row = mysql_fetch_assoc($query))
{

    ?>

    <script>

        open_box();

    </script>
    <div id="box"><?php echo $row["content"]; ?></div>
    <div class="close">X</div>
    <?php

}

?>
  • 写回答

1条回答 默认 最新

  • dopii22884 2014-06-26 05:37
    关注

    You cannot use same id for more than one element

    <div id="box"><?php echo $row["content"]; ?></div> is the culprit

    use

    <div class="box"><?php echo $row["content"]; ?></div>
        <div class="close">X</div>
    

    change style to refer for .box instead of #box

    Check this fiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?