2014-01-08 65 views
0

我想使用插件自定义确认消息。我有php表记录,每行都有删除按钮。我如何自定义确认弹出,就像下面的jquery插件一样?自定义确认弹出

<?php echo' 
<tr class="record"> 
    <td align="center"><a href="#" id="'.$row["counter"].'" class="delbutton"><img src="images/del.png"></a></td></tr>'; 
?> 
    <script> 
     $(function() { 
     $(".delbutton").click(function(){ 
     var element = $(this); 
     var del_id = element.attr("id"); 
     var info = 'id=' + del_id; 
     if(confirm("Are you want to continue ?")) 
        { 
     $.ajax({ 
      type: "GET", 
      url: "delete.php", 
      data: info, 
      success: function(){ 
      } 
     }); 
       $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast") 
       .animate({ opacity: "hide" }, "slow"); 
     } 
     return false; 
     }); 
     }); 
    </script> 

jQuery插件

<script> 
$(function() { 
$("#dialog-confirm").dialog({ 
resizable: false, 
height:140, 
modal: true, 
buttons: { 
"Delete all items": function() { 
$(this).dialog("close"); 
}, 
Cancel: function() { 
$(this).dialog("close"); 
} 
} 
}); 
}); 
</script> 
</head> 
<div id="dialog-confirm" title="Empty the recycle bin?"> 
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 
+1

检查http://stackoverflow.com/questions/43955/changing-the-default-title-of-confirm-in -javascript底线你可以做到这一点,而无需使用插件,你可以在你的PHP中使用相同的插件,如果你想 –

回答

0

希望这有助于:

<?php echo' 
    <tr class="record"> 
     <td align="center"><a href="#" id="'.$row["counter"].'" class="delbutton"><img src="images/del.png"></a></td></tr>'; 
    ?> 
    <script> 
     $(function() { 
     $(".delbutton").click(function(){ 
      var element = $(this); 
      var del_id = element.attr("id"); 
      var info = 'id=' + del_id; 
      $("#dialog-confirm").dialog({ 
        resizable: false, 
        height:140, 
        modal: true, 
        buttons: { 
        "Delete all items": function() {       
         $.ajax({ 
         type: "GET", 
         url: "delete.php", 
         data: info, 
         success: function(){ 
          $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast").animate({ opacity: "hide" }, "slow"); 
         } 
         }); 
         $(this).dialog("close"); 
        }, 
        Cancel: function() { 
         $(this).dialog("close"); 
         return false; 
        } 
        } 
       }); // end Dialog   
      return false; 
     }); // end .delbtn 
    }); // end jquery load 
    </script> 
+0

该项目被删除,但删除记录的动画丢失。 – user3097736

+0

您可以尝试以下$(this).parents(“。record”)。fadeOut('slow')'而不是'$(this).parents(“。record”)。animate({backgroundColor: fbc7c7“},”fast“)。animate({opacity:”hide“},”slow“);'。希望这个帮助 – Anunay

0

如果您需要更多的帮助,就问我。

"Delete all items": function() { 
// insert your ajax here 
$(this).dialog("close"); 
}, 

参考:.dialog()

+0

我试过但不工作 – user3097736