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
how to add delete confirmation message
提问by Monk L
In HTML, delete_icon
is 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_icon
is clicked. The popup mentioned above should open and if yes
is clicked, the instance should get deleted, otherwise it should return the same. How can I achieve this in jQuery
or 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;
}
});
});
}
});
});