1

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

これが2番目の部分です:

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

編集:ロード時に表示されるメッセージを受け取りました。2番目の部分のコードをに変更しました

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

4

2 に答える 2

3

のようなダイアログウィンドウ、この画像をご覧ください:

ここに画像の説明を入力してください

そして、この例を確認してください:http ://www.ericmmartin.com/projects/simplemodal/

ポップモデルにはさまざまな種類があります:http ://www.ericmmartin.com/projects/

およびコーディングサンプル:http ://www.ericmmartin.com/projects/simplemodal/#examples

于 2012-11-20T04:32:10.280 に答える
1

これをページに置いてください。

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

});
于 2012-11-20T04:35:25.267 に答える