문제

I am using DataTables to display row data, in the last column on the right have have 2 images, one for edit and one for delete. In order to trap the click event I use:

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

A friend gave me this code to try..

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

Which works when I use it like:

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

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

 });

I am confused about the callback part because when I click "Cancel" the box goes away but the page is still grayed out and locked. What I want to do is if the user clicks cancel to end and go back to normal and if the user clicks "Ok" then I need to pass var rowID to a file "delete_row.php"... But this is new territory for me.. If it was a simple html link I can get the .val and be done but in DataTables I don't have that option..

Can anyone here point me in the right direction? I've googled this to death but am unable to find information on my usage requirements.

도움이 되었습니까?

해결책

The fancyConfirm function is expecting callback function, when not given there is error in the fancybox onclosed event which might explain why it stay gray.

Try changing the call to:

fancyConfirm("Are you sure you want to delete this record?", function(ret) { })
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top