简体   繁体   中英

Jquery Popup Box

I'm new to JavaScript and Jquery. I googled Jquery pop-up examples online. I want the message to say "Our website is not yet complete, but feel free to browse what we have." I'll include the code example I found, but it looks really weird. I'm not sure what the name of the function is and how to execute it using the window.onload = function(); code. I also want to have a button 'close' that closes the text box. Here'a what it should look like: http://demo.tutorialzine.com/2010/12/better-confirm-box-jquery-css3/

Here's the first part:

    (function($){

    $.confirm = function(params){

        if($('#confirmOverlay').length){
            // A confirm is already shown on the page:
            return false;
        }

        var buttonHTML = '';
        $.each(params.buttons,function(name,obj){

            // Generating the markup for the buttons:

            buttonHTML += '<a href="#" class="button '+obj['class']+'">'+name+'<span></span></a>';

            if(!obj.action){
                obj.action = function(){};
            }
        });

        var markup = [
            '<div id="confirmOverlay">',
            '<div id="confirmBox">',
            '<h1>',params.title,'</h1>',
            '<p>',params.message,'</p>',
            '<div id="confirmButtons">',
            buttonHTML,
            '</div></div></div>'
        ].join('');

        $(markup).hide().appendTo('body').fadeIn();

        var buttons = $('#confirmBox .button'),
            i = 0;

        $.each(params.buttons,function(name,obj){
            buttons.eq(i++).click(function(){

                // Calling the action attribute when a
                // click occurs, and hiding the confirm.

                obj.action();
                $.confirm.hide();
                return false;
            });
        });
    }

    $.confirm.hide = function(){
        $('#confirmOverlay').fadeOut(function(){
            $(this).remove();
        });
    }

})(jQuery);

Here's the second part:

$(document).ready(function(){

    $('.item .delete').click(function(){

        var elem = $(this).closest('.item');

        $.confirm({
            'title'     : 'Delete Confirmation',
            'message'   : 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?',
            'buttons'   : {
                'Yes'   : {
                    'class' : 'blue',
                    'action': function(){
                        elem.slideUp();
                    }
                },
                'No'    : {
                    'class' : 'gray',
                    'action': function(){}  // Nothing to do in this case. You can as well omit the action property.
                }
            }
        });

    });

});

            $(markup).hide().appendTo('body').fadeIn();

            var buttons = $('#confirmBox .button'),
                i = 0;

            $.each(params.buttons,function(name,obj){
                buttons.eq(i++).click(function(){

                    // Calling the action attribute when a
                    // click occurs, and hiding the confirm.

                    obj.action();
                    $.confirm.hide();
                    return false;
                });
            });
        }

        $.confirm.hide = function(){
            $('#confirmOverlay').fadeOut(function(){
                $(this).remove();
            });
        }

    })(jQuery);

EDIT: I got the message to show up on loading. I changed the code in the second part to

$('.item .delete').ready(function(){

Dialog window like, please see this image :

在此输入图像描述

And please check this example: http://www.ericmmartin.com/projects/simplemodal/

There is various types of pop models: http://www.ericmmartin.com/projects/

And coding samples: http://www.ericmmartin.com/projects/simplemodal/#examples

Put this on the page.

Make sure that the first part of your question is also included.

It will make a dialog box on the page center with a message and with a close button.

Also you can change the Heading, I just added a placeholder.

$(document).ready(function(){
  $.confirm({
    'title'     : 'Heading Goes Here',
    'message'   : 'Our website is not yet complete, '
                  + 'but feel free to browse what we have.',
    'buttons'   : {
        'Close'   : {
          'class' : 'blue',
          'action': function(){}  // Nothing to do in this case.
        }
    {
  });

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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