2011-08-27 70 views
0

证实我有这样的jQuery代码: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继续。

回答

2

我有两个建议:

  1. 使用jQuery data API
    这里的想法是存储在已知位置的相应信息,并使用你的对话框内。例如:

    $("#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; 
    }); 
    
  2. 需要时用相应的按钮修改对话框。这可能是太冗长了,虽然和更多的工作比它的价值加上创造了很多对象的开销。

    $("#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; 
    });