简体   繁体   English

删除记录动画不适用于对话框确认

[英]Delete record animation isn't working with dialog-confirm

Okay, what I have here is a Ajax delete record. 好的,我这里是Ajax删除记录。 I've tried to add jquery dialog-confirm instead of using javascript confirm. 我试图添加jQuery对话框确认,而不是使用JavaScript确认。 The delete function works but the problem is the animation of deleting row was not working. 删除功能有效,但问题是删除行的动画无效。

Here's what I have right now. 这就是我现在所拥有的。 http://jsfiddle.net/altaire/YJC44/ http://jsfiddle.net/altaire/YJC44/

Any help will appreciate. 任何帮助将不胜感激。 Thanks! 谢谢!

Php p

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 jQuery /阿贾克斯

 $(".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");
});

You have to add a js as "//code.jquery.com/ui/1.11.0/jquery-ui.js". 您必须将js添加为“ //code.jquery.com/ui/1.11.0/jquery-ui.js”。 see below demo. 参见下面的演示。

<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>

Try this 尝试这个

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

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

You are trying to animate the $("#dialog") if you use $(this). 如果您使用$(this),则尝试为$(“#dialog”)设置动画。

DEMO : http://jsfiddle.net/yeyene/YJC44/1/ 演示: 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");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM