2014-03-06 60 views
0

嗨我試圖讓確認對話框(Bootbox)的工作。它顯示確認對話框,但按下確定按鈕後不執行任何操作。Bootbox ASP.NET MVC確認

$(document).on("click", "#close", function (e) { 
      e.preventDefault(); 
      var $this = $(this); 
      bootbox.confirm("Are you sure you want to close this Service Request? This operation cannot be reversed." 
       , function (result) { 
        if (result) { 
         $this.closest('form').submit(); 
        } else { 
         console.log("user declined"); 
        } 
       }); 
     }); 

我認爲這是錯誤的:

$this.closest('form').submit(); 

我的按鈕是<td><a href="@Url.Action("CloseLog", "Log", new {id = item.LogID})"><span class="glyphicon glyphicon-trash" id="close"></span></a>

問題是我如何才能確定按鈕的工作?

編輯: 我可以通過點擊按鈕調用這個函數嗎?如果是這樣如何?

$(document).on("click", ".alert", function (e) { 
      var link = $(this).attr("href"); // "get" the intended link in a var 
      e.preventDefault(); 
      bootbox.confirm("Are you sure?", function (result) { 
       if (result) { 
        document.location.href = link; // if result, "set" the document location  
       } 
      }); 
     }); 
+0

你的意思是你按確定後沒有任何反應?準確地說是 – VladL

+0

。沒有任何反應 – ASPCoder1450

+0

$是元標誌,不要將它用作變量名稱的一部分,試試$(this).closest('form')。submit(); – VladL

回答

0

基於您的評論

$(document).ready(function() 
{ 
    $("#close").click(function() 
    { 
    var link = $(this).attr("href"); // "get" the intended link in a var 
    var result = confirm("Are you sure?"); 
    if(result) 
    { 
     document.location.href = link; // if result, "set" the document location  
    } 
    }); 
}); 
+0

抱歉沒有工作。它根本不顯示任何對話框,只是繼續刪除 – ASPCoder1450

+0

我是否需要以任何方式更改我的按鈕/鏈接? – ASPCoder1450

+0

@ ASPCoder1450和現在? – VladL