如何jquery提醒确认框“是”& “没有”

时间:2014-09-19 08:11:07

标签: jquery html

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

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

DEMO

3 个答案:

答案 0 :(得分:30)

请参阅以下代码段:

&#13;
&#13;
$(document).on("click", "a.deleteText", function() {
    if (confirm('Are you sure ?')) {
        $(this).prev('span.text').remove();
    }
});
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:6)

我不会编写您的代码,但您要查找的内容类似于jquery对话框

看看这里

<强> jQuery modal-confirmation

$(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>

答案 2 :(得分:5)

此插件可以帮助您,

craftpip/jquery-confirm

易于设置并具有一系列强大功能。

$.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?');
            }
        }
    }
});

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

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