使用JS角创建删除按钮确认警报 [英] Create a confirmation alert for delete button in Angular using JS

查看:135
本文介绍了使用JS角创建删除按钮确认警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了一个删除按钮形式,我想创建点击删除按钮时弹出窗口确认框。删除按钮当前工作。我曾尝试在JavaScript几件事情,没有运气。我使用的角度。

这是最好的办法了吗?

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

  $(文件)。就绪(函数(){
  $(形式)验证()。
  $(半径小的成功按钮)ConfirmDialog('你确定吗?')。
});


解决方案

似乎是一个AngularJS指令是有点过分了顶的解决了这一点。似乎更容易只是除非你需要一些自定义的功能添加到您使用直接的JavaScript确定()函数。

 如果(确认(你确定要删除吗?')){
     // TODO:在这里做一些如果答案是确定。
}

希望这有助于欢呼声


  

更新:其实,有棱有角,倒不如使用$ window.confirm因为这将让你与噶/茉莉花测试


I have a form that has a delete button, I would like to create a confirmation box that pop ups when the delete button is clicked. The delete button currently works. I have tried several things in javascript with no luck. I am using Angular.

Is this best approach for this?

Also, does anyone know of any examples for this, I have not found any that work.

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

解决方案

Seems like an AngularJS directive is a bit over-the-top for a solution to this. Seems easier just to use straight javascript unless you need some custom functionality to your "confirm()" function.

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

Hope this helps, cheers

UPDATE: Actually, with Angular, it would be better to use $window.confirm as this would allow you to test with Karma/Jasmine.

这篇关于使用JS角创建删除按钮确认警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆