3

jQueryダイアログの新しいオプションを作成および追加するにはどうすればよいですか? 例: 設定オプションを介して、タイトル バーの表示を制御したり、閉じるボタンを表示したりできることが気に入っています。

スクリプトは次のようになります。

$("#message").dialog({
  showTitle:false,     //new option (hide Title bar)
  showCloseButton:true //new option (show close button)
  modal:true...        //other options
})
4

2 に答える 2

8

jQuery UI 1.9 から、新しいウィジェットを作成しなくても、はるかに優れた方法でウィジェットを拡張できます。

http://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/

参照 - ウィジェットの再定義。

$.widget( "ui.dialog", $.ui.dialog, {
    open: function() {
        console.log( "open" );
        return this._super();
    }
});

$( "<div>" ).dialog();
于 2014-01-06T04:13:09.603 に答える
6

コメントで表現したよりも少し簡単です。

// store old method for later use
var oldcr = $.ui.dialog.prototype._create;
// add the two new options with default values
$.ui.dialog.prototype.options.showTitlebar = true;
$.ui.dialog.prototype.options.showClosebutton = true;
// override the original _create method
$.ui.dialog.prototype._create = function(){
    oldcr.apply(this,arguments);
    if (!this.options.showTitlebar) {
       this.uiDialogTitlebar.hide();
    }
    else if (!this.options.showClosebutton) {
       this.uiDialogTitlebar.find(".ui-dialog-titlebar-close").hide();
    }
};

// this is how you use it
$("<div />").dialog({
    showClosebutton: false
});
// or
$("<div />").dialog({
    showTitlebar: false
});

明らかに、タイトルバーが非表示の場合、タイトルバーの一部であるため、閉じるボタンも非表示になります。

于 2012-06-05T18:09:56.213 に答える