javascript 如何添加删除确认消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17043974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:52:59  来源:igfitidea点击:

how to add delete confirmation message

javascriptjquerydjangodjango-templates

提问by Monk L

In HTML, delete_iconis an image class in which if I click it, the email idgets deleted without any confirmation message. I want to add a popup to display when delete_iconis clicked. The popup mentioned above should open and if yesis clicked, the instance should get deleted, otherwise it should return the same. How can I achieve this in jQueryor JavaScript?

在 HTML 中,delete_icon是一个图像类,如果我在其中单击它,电子邮件 ID将被删除而没有任何确认消息。我想添加一个弹出窗口以在delete_icon单击时显示。上面提到的弹出窗口应该打开,如果yes点击,实例应该被删除,否则它应该返回相同的。我怎样才能在jQuery或 中实现这一目标JavaScript

回答by Raghav Rach

You can better use as follows

你可以更好地使用如下

 <a href="url_to_delete" onclick="return confirm('Are you sure want to dele');">Delete</a>

回答by Edwin Lunando

Hmm. You do this with simple javascript.

唔。您可以使用简单的 javascript 来完成此操作。

<script type="text/javascript">
function deleteImage(x){
    var conf = confirm("Are you sure you want to delete this image?");
    if(conf == true){
        alert("OK... you chose to proceed with deletion of "+x);
    }
}
</script>

Using the default browser confirmation box. And this is the example use of the function.

使用默认浏览器确认框。这是该功能的示例使用。

<input name="myBtn" type="button" onClick="deleteImage('images/pic.jpg')" value="Delete Image">

回答by sangram parmar

try this

试试这个

 $('.delete_icon').click(function(){
        if(confirm('Are sure want to delete record?'))
        {
  var obj = $(this)
 var csrf_token = "{{ csrf_token }}";
 var email =  $(this).attr('value');
 var id =  $(this).attr('id');
 $.ajax({ 
  data:{csrfmiddlewaretoken: csrf_token,id:id,cancel_email:email},
  type:'POST',
  url: '/report/notification/', 
  cache:false,
  success: function(response) { 
      $(obj).parent('p').remove();
      return false;
   }
  });
});
}

});

});