简体   繁体   English

在jQuery 1.4.2中添加一个简单的确认/取消对话框

[英]Adding a simple confirm/cancel dialog in jQuery 1.4.2

I have put a clickable span into every list item and it works fine. 我在每个列表项中都放置了一个可点击范围,并且效果很好。 For the moment it invokes a simple alert. 目前,它调用了一个简单的警报。

Now I would like to add a simple cancel/confirm dialog. 现在,我想添加一个简单的取消/确认对话框。 Each selection should call a function. 每个选择都应调用一个函数。

Here is my code (note the alert where the span click invokes): 这是我的代码(请注意跨度单击所调用的警报):

<%@ Reference Control="~/KPIP/Controls/MultiUpload.ascx" %>
<%@ Register Src="~/KPIP/Controls/MultiUpload.ascx" TagName="MultiUpload" TagPrefix="tetrada" %>

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Entry.aspx.vb" Inherits="KPIP_Entry" %>


        var barcodes = { <%# BarcodeArray %> }



        kpip.viewAttachment = function (url) {
            $("#entryViewer").attr("src", "../Viewer.aspx?image=" + url);
        }


        function resizeViewer() {
            $("#entryViewer").hide();
            $("#attachments").hide();
            $("#entryViewer").width($("#entryForm").width() - 320 - 4);
            $("#entryViewer").height($("#entryForm").height() - $("#header").height() - 4);
            $("#attachments").height($("#entryForm").height() - $("#header").height() - 4);
            $("#attachments").show();
            $("#entryViewer").show();
        }

        $(function () {
            $.each(barcodes, function(key, value) {
                $("#barcodesList").append("<li>" + key + "</li>");
            });

            deleteButton = $('<span />').addClass('deleteButton').text('Delete');
            $('ul#barcodesList li').append(deleteButton);


            if ($("#barcodesList").children().size() > 0) {
                $("#barcodesList").after('<div id="barcodesShadow" class="cc_panelShadow"></div>');
            }


            $("#barcodesList > li").click(function () {
                $(this).children(".children").toggle();
                $("#barcodesList > li").removeClass("clicked");
                $(this).addClass("clicked");
                $("#selectedBarcode").val($(this).text());

                var params = '{ barcode : "' + $(this).text() + '", path : "' + barcodes[$(this).text()] + '" }';
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Entry.aspx/Attach",
                    dataType: "json",
                    data: params,
                    success: function () {
                        $("#dummyPostbackButton").click();
                    },
                    error: function (request, status, error) {
                        alert("Error attaching barcode file.");
                    }
                });
            });

            $("#barcodesList > li > span").click(function(e) {
               e.stopPropagation();
               var partxt = $(this).parent().clone().children().remove().end().text();
               alert(partxt);
            });

            $(window).bind("resize", function () {
                setTimeout(function () { resizeViewer(); }, 10);
            });
            setTimeout(function () { resizeViewer(); }, 10);

            $("#barcodesList > li").each(function () {
                if ($(this).text() != $("#selectedBarcode").val()) { return; }
                $(this).addClass("clicked");
            });
        });

    </script>
</head>
<body>
    <form id="entryForm" runat="server">
    <div id="header" class="ContentHeader">
        <asp:Label runat="server" CssClass="ContentHeaderLabel" Text="<%$ Resources: Header.Text %>"/>
    </div>
    <div id="attachments">
        <asp:Label class="tetradaGroupLabel" runat="server" Text="<%$ Resources: AttachmentsPanel.Text %>" />
        <tetrada:MultiUpload ID="upload" runat="server" />
        <asp:Panel ID="BarcodesListPanel" runat="server">
            <asp:Label class="tetradaGroupLabel" runat="server" Text="<%$ Resources: BarcodesPanel.Text %>" />
            <ul id="barcodesList"></ul>
        </asp:Panel>
        <asp:HiddenField ID="selectedBarcode" runat="server" />
        <asp:Button ID="dummyPostbackButton" runat="server" CausesValidation="false" />
    </div>
    <iframe id="entryViewer" frameborder="0" runat="server"></iframe>
    </form>
</body>
</html>

I tried putting dialog in several places and opening it in click event, but nothing happens. 我尝试将对话框放在多个位置并在click事件中将其打开,但没有任何反应。 Can some one please help me out here? 有人可以帮我吗?

Best regards, no9. 最好的问候,没有。

If bu simple you mean native,use confirm instead of alert; 如果您是本地人,请使用“确认”而不是“警报”;

confirm("Your Text")//Return true if user pressed ok
// false otherwise

so you can do something like: 因此您可以执行以下操作:

if(confirm("Your Text")){
//do stuff
}

有一个插件: 简单确认对话框 (我想还有很多其他类似的插件)。

If you want to add a confirm dialog box to your code 如果要在代码中添加确认对话框

It looks like 看起来像

var choice = confirm("Are you sure?");

And validates if the user clicks yes || no 并验证用户是否单击“ yes || no yes || no

if(choice == true) { //then do something here }

Hope it helps.. 希望能帮助到你..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM