jQuery jQuery删除确认框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10310004/
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-08-26 09:07:29  来源:igfitidea点击:

jQuery delete confirmation box

jquery

提问by shanish

In my jQuery am displaying my results in a table formatted output, a part of my jQuery is

在我的 jQuery 中,我在表格格式的输出中显示我的结果,我的 jQuery 的一部分是

<td class='close' onclick='deleteItem(#ITEMID,#ITEMNAME)'></td>

here "close"is a CSS class and in this class I have cross mark image, if I click this cross mark the function(deleteItem) will be fired.

"close"是一个 CSS 类,在这个类中我有十字标记图像,如果我点击这个十字标记,函数(deleteItem)将被触发。

here what I want to do is if I click this cross mark a "delete confirmation box"should pop up and if I click yes this onclick event should fire, else if I click No nothing should happen.

这里我想要做的是,如果我点击这个十字标记,一个"delete confirmation box"应该弹出,如果我点击是这个 onclick 事件应该触发,否则如果我点击 No 什么都不应该发生。

How can I achieve this, can anyone help me....

我怎样才能做到这一点,任何人都可以帮助我....

回答by Māris Kise?ovs

You need to add confirm() to your deleteItem();

您需要将 confirm() 添加到您的 deleteItem();

function deleteItem() {
    if (confirm("Are you sure?")) {
        // your deletion code
    }
    return false;
}

回答by Shashank Hegde

$(document).ready(function(){
  $(".del").click(function(){
    if (!confirm("Do you want to delete")){
      return false;
    }
  });
});

回答by Umair Hamid

I used this:

我用过这个:

<a href="url/to/delete.asp" onclick="return confirm(' you want to delete?');">Delete</a>

回答by Chandresh M

Try with below code:

尝试使用以下代码:

$('.close').click(function(){
var checkstr =  confirm('are you sure you want to delete this?');
if(checkstr == true){
  // do your code
}else{
return false;
}
});

OR

或者

function deleteItem(){
    var checkstr =  confirm('are you sure you want to delete this?');
    if(checkstr == true){
      // do your code
    }else{
    return false;
    }
  }

This may work for you..

这可能对你有用..

Thanks.

谢谢。

回答by Hüseyin BABAL

function deleteItem(this) {
    if (confirm("Are you sure?")) {
          $(this).remove();
    }
    return false;
}

You can also use jquery modalin same way

您也可以以同样的方式使用 jquery modalin

JQuery version

jQuery 版本

你确定吗?
  $(document).ready(function() {
    $("#dialog-box").dialog({
      autoOpen: false,
      modal: true
    });

  $(".close").click(function(e) {
    var currentElem = $(this);
    $("#dialog-box").dialog({
      buttons : {
        "Confirm" : function() {
          currentElem.remove()
        },
        "Cancel" : function() {
          $(this).dialog("close");
        }
      }
    });

    $("#dialog-box").dialog("open");
  });
});

回答by Rony SP

Try with this JSFiddleDEMO : http://jsfiddle.net/2yEtK/3/

试试这个JSFiddle演示:http: //jsfiddle.net/2yEtK/3/

Jquery Code:

$("a.removeRecord").live("click",function(event){
   event.stopPropagation();
   if(confirm("Do you want to delete?")) {
    this.click;
       alert("Ok");
   }
   else
   {
       alert("Cancel");
   }       
   event.preventDefault();

});

回答by Wael Assaf

Try this my friend

试试这个我的朋友

  // Confirmation Message On Delete Button.

  $('.close').click(function() {
    return confirm('Are You Sure ?')
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td class='close'></td>

回答by readikus

Simply works as:

简单地工作为:

$("a. close").live("click",function(event){
     return confirm("Do you want to delete?");
});

回答by Servantwriter

Update JQuery for version 1.9.1 link for deletion is here$("#div1").find('button').click(function(){...}

更新 1.9.1 版的 JQuery 删除链接在这里$("#div1").find('button').click(function(){...}