我想要得到一个确认消息点击删除(这可能是一个按钮或图像)。如果用户选择“Ok”,那么删除就完成了,否则如果点击“Cancel”,什么都不会发生。

当点击按钮时,我尝试回显这个,但是回显的东西使我的输入框和文本框失去了它们的样式和设计。


当前回答

在按钮的onclick事件中写入以下内容:

var result = confirm("Want to delete?");
if (result) {
    //Logic to delete the item
}

其他回答

您可以更好地使用以下方法

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

onclick处理程序应该在函数调用后返回false。如。

onclick = " ConfirmDelete ();返回错误;" >

var x = confirm("Are you sure you want to send sms?");
if (x)
    return true;
else
    return false;  

它非常简单,只有一行代码

<a href="#" title="delete" class="delete" onclick="return confirm('Are you sure you want to delete this item')">Delete</a>

我认为最简单不显眼的解决方案是:

链接:

<a href="http://link_to_go_to_on_success" class="delete">Delete</a>

Javascript:

$('.delete').click(function () {
    return confirm("Are you sure?");
});