jQuery 如何jquery警报确认框“是”和“否”

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

How to jquery alert confirm box "yes" & "no"

jqueryhtml

提问by user2169710

Somebody know how to make jQuery works with my HTML and CSS. I need when I click on the button and open alert box in the centre with some text and options "yes" , "no" and when click yes to delete the text ? My code here:

有人知道如何使 jQuery 与我的 HTML 和 CSS 一起工作。我需要当我点击按钮并在中心打开带有一些文本和选项“是”、“否”的警报框时,当单击是删除文本时?我的代码在这里:

<div class="text">Some text here 
    <a href="#" class="deleteMe">
        <span class="delete-icon"> x Delete </span>
    </a>
</div>

DEMO

演示

回答by pistou

See following snippet :

请参阅以下代码段:

$(document).on("click", "a.deleteText", function() {
    if (confirm('Are you sure ?')) {
        $(this).prev('span.text').remove();
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
    <span class="text">some text</span>
    <a href="#" class="deleteText"><span class="delete-icon"> x Delete </span></a>
</div>

回答by Dwza

I won't write your code but what you looking for is something like a jquery dialog

我不会写你的代码,但你要找的东西就像一个 jquery 对话框

take a look here

看看这里

jQuery modal-confirmation

jQuery 模式确认

$(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "Delete all items": function() {
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });

<div id="dialog-confirm" title="Empty the recycle bin?">
  <p>
    <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>
    These items will be permanently deleted and cannot be recovered. Are you sure?
  </p>
</div>

回答by Boniface Pereira

This plugin can help you,

这个插件可以帮助你,

craftpip/jquery-confirm

craftpip/jquery-确认

Its easy to setup and has great set of features.

它易于设置并具有很多功能。

$.confirm({
    title: 'Confirm!',
    content: 'Simple confirm!',
    buttons: {
        confirm: function () {
            $.alert('Confirmed!');
        },
        cancel: function () {
            $.alert('Canceled!');
        },
        somethingElse: {
            text: 'Something else',
            btnClass: 'btn-blue',
            keys: ['enter', 'shift'], // trigger when enter or shift is pressed
            action: function(){
                $.alert('Something else?');
            }
        }
    }
});

Other than this you can also load your content from a remote url.

除此之外,您还可以从远程 url 加载您的内容。

$.confirm({
    content: 'url:hugedata.html' // location of your hugedata.html.
});