jQuery 使用jquery的确认框

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

Confirmation box using jquery

jquery

提问by enthusiastic

i want to make a confirmation before delete some data so how can i make it using jquery?

我想在删除一些数据之前进行确认,那么如何使用 jquery 进行确认?

回答by Barrie Reader

$('#deleteBtn').click(function() {
  if(confirm("Are you sure?")) {
    //delete here
  }
});

回答by Darin Dimitrov

One possibility is to use the javascript confirmfunction.

一种可能性是使用 javascriptconfirm函数。

$(function() {
    $('#someLink').click(function() {
        return confirm('Are you sure you want to delete this item?');
    });
});

回答by John

To make a dialog, use the jQueryUI dialog. It includes modal & non-modal dialogs as well as good visual effects and a robust date-picker. There are also some plugins available to extend jQueryUI.

要创建对话框,请使用jQueryUI 对话框。它包括模态和非模态对话框以及良好的视觉效果和强大的日期选择器。还有一些插件可用于扩展 jQueryUI。

Here's an example

这是一个例子

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/dot-luv/jquery-ui-1.8.6.custom.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="js/jquery-ui-1.8.6.custom.min.js"></script>
<script>
var setupKiller = function() {
    // Here's the text of the dialog box 
    var dialog = $("<div style='display: none'><p>Are you sure?</p></div>").appendTo("body");
    // This is the button on the form
    var button = $("<span>Kill</span>").appendTo("#killer").click(function () {
        var form = $("#killer")
        // The form button was pressed - open the dialog
        $(dialog).dialog(
        {
                title: "Confirm",
                modal: true,
                buttons: {
                    "Delete em": function () {
                        // This will invoke the form's action - putatively deleting the resources on the server
                        $(form).submit();
                        $(this).dialog("close");
                    },
                    "Cancel": function() {
                        // Don't invoke the action, just close the dialog
                        $(this).dialog("close");
                    }
                }
            });
        return false;
    });
    // Use jQuery UI styling for our button
    $(button).button();
}
</script>
</head>
<body onload="setupKiller();">
<form id='killer' method='POST'>
<p>Some Text</p>
</form>
</body>
</html>