【问题标题】:Jquery Popup BoxjQuery弹出框
【发布时间】:2012-11-20 04:16:02
【问题描述】:

我是 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(){

【问题讨论】:

  • 你想要一个弹出窗口还是一个对话框。
  • 什么意思?我希望它在页面加载时弹出。我不确定你所说的对话是什么意思。
  • 在浏览器中弹出意味着应用程序打开一个新的浏览器实例并使用相同的会话信息。对话框意味着基于 Div 的确认框打开(就像警报一样)并且它是同一页面的一部分
  • 我想我明白了你的意思,也看到了这个例子。
  • 对话框,然后。我想要一些优雅的东西而不是传统的 JavaScript 警报。

标签: javascript jquery html css popup


【解决方案1】:

对话框窗口喜欢,请看这张图:

请检查以下示例:http://www.ericmmartin.com/projects/simplemodal/

流行模特有多种类型:http://www.ericmmartin.com/projects/

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

【讨论】:

  • 谢谢。你能解释一下代码吗?另外,如何让脚本使用 onload.window 运行?
【解决方案2】:

把它放在页面上。

确保您的问题的first part 也包括在内。

它将在页面中心创建一个带有消息和关闭按钮的对话框。

你也可以更改标题,我只是添加了一个占位符。

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

});

【讨论】:

  • 汉克斯。你能解释一下代码吗?另外,如何让脚本使用 onload.window 运行?
  • first part 是一个用于对话的实用 JS。通过使用该 JS 并使用 jQuery 在页面加载时创建了一个对话框。 onload 与 jQuery 中的 $(document).ready() 相同。
  • 谢谢。在您发表最后一条评论前几分钟,我就想通了。
猜你喜欢
  • 1970-01-01
  • 2012-06-07
  • 2012-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多