0

CreateTemplate、OpenTemplate、およびその他の多くの Jquery ダイアログの設定では、ほとんど同じ設定が使用されますが、高さと幅には例外があります。

すべてのキー/値設定を含む配列の jquery .dialog() 関数ソートを渡すことは可能ですか?この配列をいつでも簡単に渡すことができますか?

   $(document).ready(function () {


        // I would like to setup here sort of an array with properties and values
        // as basis for each click-handler

            /************************* Open template ****************************/
            $('#OpenTemplate').click(function (e) {
                e.preventDefault();
                var link = this;

                $('#MyDialog').dialog({
                    open: function (e) { $(this).load($(link).attr('href')); },
                    title: link.innerHTML,
                    autoOpen: true,
                    modal: true,
                    show: 'fade',
                    hide: 'fade',
                    width: 250,
                    height: 200,
                    buttons:
                    { 
                        "OK": function () { openTemplate($(this), $('form', this)); },
                        "Cancel": function () { $(this).dialog("close"); }
                    }
                });
            });

            /************************* Create template ****************************/
            $('#CreateTemplate').click(function (e) {
                e.preventDefault();
                var link = this;

                $('#MyDialog').dialog({
                    open: function (e) { $(this).load($(link).attr('href')); },
                    title: link.innerHTML,
                    autoOpen: true,
                    modal: true,
                    show: 'fade',
                    hide: 'fade',
                    width: 250,
                    height: 200,
                    buttons:
                    {
                        "OK": function () { createTemplate($(this), $('form', this)); },
                        "Cancel": function () { $(this).dialog("close"); }
                    }
                });
            });

    });
4

1 に答える 1

0

私はこのようなことをしようとします:

var dialogObject = { title: 'Title', width: 250 };
$('#CreateTemplate').dialog(dialogObject); 

このオブジェクトには、すべてのダイアログボックスで同じになることがわかっているすべての値を含めることができます。次に高さを変更する場合は、次のようにして既存のダイアログを変更できます。

$('#dialog-confirm').attr('height', '250');

dialogObjectにボタンを追加する必要がある場合:

var dialogObject = { 
     title: 'Title', 
     width: 250,
     buttons: { 
     "Ok": function() 
      { 
        $(this).dialog("close"); 
      } 
    }   
}; 
于 2012-10-02T20:03:19.673 に答える