jQuery 内联确认(删除) - 实现问题

jQuery Inline Confirmation (delete) - Implementation Issue

本文关键字:实现 问题 删除 确认 jQuery      更新时间:2023-09-26

我正在尝试为 jquery 实现这个内联删除确认插件。下面是示例代码:

//sample code taken from plugin on GitHub: 
//https://github.com/fredwu/jquery-inline-confirmation
$("a.delete").inlineConfirmation({
  confirm: "<a href='#' class='confirm-yes'>Yes</a>",
  cancel: "<a href='#' class='confirm-no'>No</a>",
  separator: " | ",
  reverse: true,
  bindsOnEvent: "hover",
  confirmCallback: function(action) {
    action.parent().fadeIn();
  }
});

将其附加到任何选择器将显示删除或取消按钮,但我需要在单击时显示此选项。

所以我的原始代码是这样的:

jQuery( document ).ready( function( $ ) { 
            $( '#mytable button').click( function( event ) { 
            event.preventDefault(); 

            if ( ! confirm( 'Are you sure you want to continue' ) ) 
                    return; 
    var $button = $(this);
    var nonce = $( this ).attr('data-nonce');
    var rowID = $( this ).attr('value'); 
    var file = $( this ).attr('file'); 
            var data = { }
            $.post( 
                    ajaxurl, 
                    data,
                    function ( response ) { });
        }); 
}); 

该插件允许"确认回调",我需要在确认单击时执行我的代码,而不是像现在这样立即执行。 我仍在学习jQuery,所以这可能是一个简单的问题。 只需要知道如何自定义它,所以它是这样的:

jQuery( document ).ready( function( $ ) { 
$( '#mytable button').click( function( event ) { 
$(this).inlineConfirmation({
confirmCallback: (?? WHAT DO I PUT HERE??)
});

如果确认,则运行我的代码(这将是确认回调。 我该怎么做? 。发布。。。等。。。

将其附加到任何选择器将显示删除或取消按钮,但我需要在单击时显示此选项。

更改此设置:

bindsOnEvent: "hover",

对此:(尽管文档说这是默认设置)

bindsOnEvent: "click",

并添加一个回调函数,如下所示:

confirmCallback: function (a) {
     // write your code here.
}

总而言之:

jQuery(document).ready(function($) {
    $('#mytable button').inlineConfirmation({
         bindsOnEvent: "click",
         confirmCallback: function($button) {
             var nonce = $button.attr('data-nonce');
             var rowID = $button.attr('value'); 
             var file = $button.attr('file'); 
             var data = {};
             $.post( 
                ajaxurl, 
                data,
                function ( response ) { }
             );
         }
     });
});