Bootbox ASP.NET MVC确认

时间:2014-03-06 19:21:44

标签: javascript jquery asp.net asp.net-mvc bootbox

您好我正在尝试使用确认对话框(Bootbox)。它会显示确认对话框,但按下确定按钮后不会执行任何操作。

 $(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>

问题是如何让ok按钮起作用?

编辑: 我可以从onClick in按钮调用此函数吗?如果是这样怎么样?

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

1 个答案:

答案 0 :(得分: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      
     }
  });
});