javascript - Jquery 弹出框

标签 javascript jquery html css popup

我是 JavaScript 和 Jquery 的新手。我在网上搜索了 Jquery 弹出示例。我希望消息说“我们的网站尚未完成,但请随意浏览我们拥有的内容。”我将包括我找到的代码示例,但它看起来真的很奇怪。我不确定函数的名称是什么以及如何使用 window.onload = function(); 执行它。代码。我还想要一个关闭文本框的按钮“关闭”。它应该是这样的:http://demo.tutorialzine.com/2010/12/better-confirm-box-jquery-css3/

这是第一部分:

    (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);

这是第二部分:

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

编辑:我收到了在加载时显示的消息。我把第二部分的代码改成了

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

最佳答案

对话窗口之类的,请看这张图:

enter image description here

请检查这个例子:http://www.ericmmartin.com/projects/simplemodal/

有各种类型的pop模型:http://www.ericmmartin.com/projects/

和编码示例:http://www.ericmmartin.com/projects/simplemodal/#examples

关于javascript - Jquery 弹出框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13466523/

相关文章:

angularjs - 如何在输入字段中只输入 10 个数字?

javascript - nvd3 multibar - 使用不同的图例状态更新现有图表(就像单击它们一样)

带边距的 jQuery Mobile Center 输入

javascript - scrollTop 在 firefox 和 IE 中不起作用

javascript - 捕获复选框上的单击事件

jquery - IOS 8+ 上的 Chrome crweb.js 和 __gCRweb 问题

javascript - 如何在表格中实现 JavaScript 搜索过滤功能

Javascript 模块模式和 Google Closure 编译器

java - window.open 的 url 中包含法语字符

javascript - 使用 jQuery 添加的表单元素不会在 POST 上发送