2012-12-08 45 views
0

我想在rails中的鏈接上添加確認彈出窗口。由於瀏覽器的默認CSS確認:方法不能改變,我決定使用bootbox。 (http://bootboxjs.com/確認後Bootbox執行請求

比方說,我在我的Rails應用程序下面的鏈接

= link_to "asd", root_path(), id: "test" 

的JavaScript代碼如下命令可以打開一個彈出窗口,結果是否設置正確,我現在需要的是執行鏈接如果用戶批准確認,則訪問。

$("#test").click(function(e) { 
    e.preventDefault(); 
    bootbox.confirm("Are you sure?", function(result) { 
    if (result) { 
     // ??? 
    } else { 
     return false; 
    } 
    }); 
}); 

回答

0
$("#test").click(function(e) { 
    e.preventDefault(); 
    bootbox.confirm("Are you sure?", function(result) { 
    if (result) { 
     window.open($(this).attr("href"),"_self"); 
    }); 
}); 

我想通了:這不是牛逼複雜可言,我很驚訝,沒有人回答:-(