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

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


当前回答

下面是纯JS中使用className和绑定事件的另一个简单例子。

var eraseable = document.getElementsByClassName("eraseable"); for (var i = 0; i < eraseable.length; i++) { eraseable[i].addEventListener('click', delFunction, false); //bind delFunction on click to eraseables } function delFunction(){ var msg = confirm("Are you sure?"); if (msg == true) { this.remove(); //remove the clicked element if confirmed } }; <button class="eraseable"> <img class="eraseable" src="http://zelcs.com/wp-content/uploads/2013/02/stackoverflow-logo-dumpster.jpg" style="width:100px;height:auto;"> Delete me</button> <button class="eraseable"> <img class="eraseable" src="http://zelcs.com/wp-content/uploads/2013/02/stackoverflow-logo-dumpster.jpg" style="width:100px;height:auto;"> Delete me</button> <button class="eraseable"> <img class="eraseable" src="http://zelcs.com/wp-content/uploads/2013/02/stackoverflow-logo-dumpster.jpg" style="width:100px;height:auto;"> Delete me</button>

其他回答

HTML

<input onclick="return myConfirm();" type="submit" name="deleteYear" class="btn btn-danger" value="Delete">

Javascript

<script>
function myConfirm() {
  var result = confirm("Want to delete?");
  if (result==true) {
   return true;
  } else {
   return false;
  }
}

function ConfirmDelete()
{
  return confirm("Are you sure you want to delete?");
}


<input type="button" onclick="ConfirmDelete()">

非常简单

function archiveRemove(any) {
    var click = $(any);
    var id = click.attr("id");
    swal.fire({
        title: 'Are you sure !',
           text: "?????",
           type: 'warning',
           showCancelButton: true,
           confirmButtonColor: '#3085d6',
           cancelButtonColor: '#d33',
           confirmButtonText: 'yes!',
           cancelButtonText: 'no'
    }).then(function (success) {
        if (success) {
            $('a[id="' + id + '"]').parents(".archiveItem").submit();
        }
    })
}

我想提供我的方法:

<form action="/route" method="POST">
<input type="hidden" name="_method" value="DELETE"> 
<input type="hidden" name="_token" value="the_token">
<button type="submit" class="btn btn-link" onclick="if (!confirm('Are you sure?')) { return false }"><span>Delete</span></button>
</form>
var txt;
var r = confirm("Press a button!");
if (r == true) {
   txt = "You pressed OK!";
} else {
   txt = "You pressed Cancel!";
}

var txt; var r =确认(“按下按钮!”); 如果(r == true) { txt = "You pressed OK!"; }其他{ txt = "You pressed Cancel!"; }