19

我有一个带有删除按钮的表单,我想创建一个确认框,在单击删除按钮时弹出。删除按钮当前有效。我在javascript中尝试了几件事,但没有运气。我正在使用角。

这是最好的方法吗?

另外,有没有人知道这方面的任何例子,我还没有找到任何工作。

$(document).ready(function(){
  $("form").validate();
  $(".radius small success button").ConfirmDialog('Are you sure?');
});
4

5 回答 5

42

似乎 AngularJS 指令对于解决这个问题有点过头了。除非您需要为“confirm()”函数添加一些自定义功能,否则直接使用 javascript 似乎更容易。

if (confirm('Are you sure you want to delete this?')) {
     // TODO:  Do something here if the answer is "Ok".
}

希望这有帮助,干杯

更新:实际上,对于 Angular,使用 $window.confirm 会更好,因为这将允许您使用 Karma/Jasmine 进行测试。

于 2014-05-15T14:22:45.930 回答
29

是另一种方法。基本上,它是一个指令,用于获取您要显示的警告字符串,以及在用户接受时调用的函数。使用示例:

<button type="button" ng-really-message="Are you sure?"
ng-really-click="delete()">Delete</button>
于 2013-11-12T13:16:40.630 回答
9

这就是我们处理“确认对话框”的方式(使用引导程序)

标记

<div class="alert alert-block alert-error notification fade in" data-ng-show="displayLocationDeletePopup">
    <h6>Are you sure you want to delete this location?</h6>
    <div class="form-controls-alert">
        <a href="" class="btn" data-ng-click="showDeleteLocationPopup(false)">No</a>
        <a href="" class="btn btn-danger" data-ng-click="deleteVendorLocation(locationId)">Yes</a>
    </div>
</div><!-- end alert -->    

在控制器加载时将模型设置为 false 以默认隐藏ng-show

$scope.displayLocationDeletePopup = false;

单击显示弹出窗口的事件时,调用函数/传递模型

<i class="icon-remove" data-ng-click="showDeleteLocationPopup(true, location)"></i>

在控制器中:

$scope.showDeleteLocationPopup = function(options, id) {
    if (options === true) {
        $scope.displayLocationDeletePopup = true;
    } else {
        $scope.displayLocationDeletePopup = false;
    }
    $scope.locationId = id;
};

根据上面 html 中的锚点,可以关闭弹出窗口或运行函数

$scope.deleteVendorLocation = function (storeLocation) {
   // Code to run on confirmation            
};
于 2013-03-14T22:25:47.103 回答
-1
var r = confirm("Are you sure you want to Permanently delete this order?");
if (r == true) {
    (OK button click) Write the function here.....
} else {
    (Cancle button click) Write the function here.....
}
于 2016-07-01T11:49:00.553 回答
-1

将删除选项放在每条记录的右侧,单击删除选项后,记录应从详细信息和 JSON 数组中删除。

于 2017-08-09T06:48:29.317 回答