删除记录动画无法使用dialog-confirm

时间:2014-08-01 06:56:03

标签: javascript jquery ajax

好的,我这里有一个Ajax删除记录。我试图添加jquery对话框 - 确认而不是使用javascript确认。删除功能有效,但问题是删除行的动画无效。

这就是我现在所拥有的。 http://jsfiddle.net/altaire/YJC44/

任何帮助都会表示赞赏。谢谢!

while($row = $result->fetch_assoc()){
echo'<tr class="records">';
echo'<td>'.$i++.'</td>
<td align="center"><a href="#" name="'.$row["counter"].','.$row["idas"].'" class="delbuttons"><img src="images/del.png" border="0" width="10" height="10" title="Delete"></a></td>
<tr>;

的Jquery / AJAX

 $(".delbuttons").click(function () {
//e.preventDefault();
var element = $(this);
var del_id = element.attr("name");
var info = 'prdelete=' + del_id;

$("#dialog").dialog({
    buttons: {
        "Confirm": function () {
            $.ajax({
                type: "GET",
                url: "delete.php",
                data: info,
                success: function () {}
            });
            $(this).parents(".records").animate({
                backgroundColor: "#fbc7c7"
            }, "fast")
                .animate({
                opacity: "hide"
            }, "slow", function () {
                setTimeout(function () {
                    window.location.reload();
                }, 1000);
            });
            $(this).dialog("close");
        },
            "Cancel": function () {
            $(this).dialog("close");
        }
    }
});

$("#dialog").dialog("open");
});

2 个答案:

答案 0 :(得分:0)

您必须添加一个js作为&#34; // code.jquery.com/ui/1.11.0/jquery-ui.js"。见下面的演示。

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script> 
$(document).ready(function(){
   $( "#effect" ).animate({backgroundColor: "#aa0000",color: "#fff",width: 500},5000);

});
</script> 
</head>
<body>
<div id="effect"style="border:1px solid red;height:100px;width:100px;position:absolute;">
</div>
</body>
</html>

答案 1 :(得分:0)

试试这个

$('a[name="'+del_id+'"]').parents(".records")...

而不是$(this).parents(".records")...

如果您使用$(this),则试图为​​$(“#dialog”)设置动画。

DEMO:http://jsfiddle.net/yeyene/YJC44/1/

$(".delbuttons").click(function () {
//e.preventDefault();
var element = $(this);
var del_id = element.attr("name");
//alert(del_id);
var info = 'prdelete=' + del_id;

$("#dialog").dialog({
    buttons: {
        "Confirm": function () {
            $.ajax({
                type: "GET",
                url: "delete.php",
                data: info,
                success: function () {
                     // $(this).parents(".records")
                     $('a[name="'+del_id+'"]').parents(".records")
                     .css({'background': '#fbc7c7'})
                     .animate({             
                         opacity: 0
                     }, 1000, function () {
                         setTimeout(function () {
                             window.location.reload();
                         }, 1000);
                     });
                    $(this).dialog("close");
                }
            });
        },
            "Cancel": function () {
            $(this).dialog("close");
        }
    }
});
$("#dialog").dialog("open");
});