1

我正在使用 DataTables 显示行数据,在右侧的最后一列中有 2 张图像,一张用于编辑,一张用于删除。为了捕获我使用的点击事件:

 $('#datatable tbody tr a.delete img').live( 'click', function () {
        });

一个朋友给了我这个代码来试试..

function fancyAlert(msg) {
        jQuery.fancybox({
        'modal' : true,
        'content' : "<div style=\"margin:1px;width:240px;\">"+msg+"<div style=\"text-align:right;margin-top:10px;\"><input style=\"margin:3px;padding:0px;\" type=\"button\" onclick=\"jQuery.fancybox.close();\" value=\"Ok\"></div></div>"
        });
    }

    function fancyConfirm(msg,callback) {
        var ret;
        jQuery.fancybox({
            modal : true,
            content : "<div style=\"margin:1px;width:240px;\">"+msg+"<div style=\"text-align:right;margin-top:10px;\"><input id=\"fancyConfirm_cancel\" style=\"margin:3px;padding:0px;\" type=\"button\" value=\"Cancel\"><input id=\"fancyConfirm_ok\" style=\"margin:3px;padding:0px;\" type=\"button\" value=\"Ok\"></div></div>",
            onComplete : function() {
                jQuery("#fancyConfirm_cancel").click(function() {
                    ret = false;
                    jQuery.fancybox.close();
                })
                jQuery("#fancyConfirm_ok").click(function() {
                    ret = true;
                    jQuery.fancybox.close();
                })
            },
            onClosed : function() {
                callback.call(this,ret);
            }
        });
    }

    function fancyConfirm_text() {
        fancyConfirm("Ceci est un test", function(ret) {
        alert(ret)
        })
    }

当我像这样使用它时,它会起作用:

$('#datatable tbody tr a.delete img').live( 'click', function () {

     if (!fancyConfirm("Are you sure you want to delete this record?"))
            e.preventDefault();

 });

我对回调部分感到困惑,因为当我单击“取消”时,该框消失了,但页面仍然灰显并锁定。我想要做的是,如果用户单击取消结束并恢复正常,如果用户单击“确定”,那么我需要将 var rowID 传递给文件“delete_row.php”......但这是新领域我..如果它是一个简单的 html 链接,我可以获得 .val 并完成,但在 DataTables 中我没有那个选项..

这里有人能指出我正确的方向吗?我已经用谷歌搜索了这个,但无法找到关于我的使用要求的信息。

4

1 回答 1

1

fancyConfirm函数期待回调函数,当没有给出时,fancyboxonclosed事件中有错误,这可能解释了为什么它保持灰色。

尝试将调用更改为:

fancyConfirm("Are you sure you want to delete this record?", function(ret) { })
于 2010-12-28T15:23:34.133 回答