Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery加载单击的链接(如果从对话框中确认)_Jquery_Jquery Ui Dialog - Fatal编程技术网

Jquery加载单击的链接(如果从对话框中确认)

Jquery加载单击的链接(如果从对话框中确认),jquery,jquery-ui-dialog,Jquery,Jquery Ui Dialog,我有这个jquery代码: $("#deletec-box").dialog({ autoOpen:false, resizable:false, height:230, modal:true, buttons:{ "Confirm":function(){ window.location=$("a[id*='deletec-confirm']").attr('href'); $(th

我有这个jquery代码:

    $("#deletec-box").dialog({
    autoOpen:false,
    resizable:false,
    height:230,
    modal:true,
    buttons:{
        "Confirm":function(){
            window.location=$("a[id*='deletec-confirm']").attr('href');
            $(this).dialog("close");
        },Cancel:function(){
            $(this).dialog("close");
        }
    }
});

$("a[id*='deletec-confirm']").click(function(){
    $("#deletec-box").dialog("open");
    return false;
});
在网页中,我有:

<a href="?action=delc&cid=2" id="deletec-confirm2" title="Delete This Record">Delete</a>
<a href="?action=delc&cid=3" id="deletec-confirm3" title="Delete This Record">Delete</a>


单击上面的第二个链接时,它将使用第一个链接url加载。如何让jquery对话框根据上面单击的链接获得正确的url?我只想做的是,如果他们单击要求确认的删除链接,如果他们单击对话框中的确认按钮,我希望他们最初单击的url继续。我有两个建议:

  • 使用
    这里的想法是将适当的信息存储在已知位置,并在对话框中使用这些信息。例如:

    $("#deletec-box").dialog({
        autoOpen:false,
        resizable:false,
        height:230,
        modal:true,
        buttons:{
            "Confirm":function(){
                window.location=$('#deletec-box').data('loc');
                $(this).dialog("close");
            },Cancel:function(){
                $(this).dialog("close");
            }
        }
    });
    
    $("a[id*='deletec-confirm']").click(function(){
        $('#deletec-box').data('loc', $(this).attr('href'));
        $("#deletec-box").dialog("open");
        return false;
    });
    
  • 在需要时使用适当的按钮修改对话框。不过,这可能太冗长了,需要做的工作太多,再加上创建大量对象的开销

    $("#deletec-box").dialog({
        autoOpen:false,
        resizable:false,
        height:230,
        modal:true,
    });
    
    $("a[id*='deletec-confirm']").click(function(){
        loc = $(this).attr('href');
        $('#deletec-box').dialog({
            buttons:{
                    "Confirm":function(){
                        window.location=loc;
                        $(this).dialog("close");
                    },Cancel:function(){
                        $(this).dialog("close");
                    }
            }
        });
        $("#deletec-box").dialog("open");
        return false;
    });