2012-04-18 8 views
1

のボタン上のクラスの追加:は、私はjQueryのダイアログを持っている私のjqueryのダイアログ

// Configure buttons 
    var dialogButtons = {}; 

    dialogButtons[buttonConfirm] = function() { 
     $.ajax({ 
      type: "Post", 
      url: href, 
      cache: false, 
      success: function (data) { var func = success; window[func](data); } 
     }); 
     $(this).dialog("close"); 
    }; 

    dialogButtons[buttonCancel] = function() { 
     $(this).dialog("close"); 
    }; 

    // Configure dialog 
    $dialog.dialog(
     { 
      modal: true, 
      closeOnEscape: true, 
      resizable: false, 
      buttons: dialogButtons 
     }); 

    // Opening dialog 
    $dialog.dialog('open'); 

を私の質問:私は私のボタン上の特定のクラスのBTN 'を設定したいと思います。これどうやってするの?

おかげ

+1

を実証していますなぜあなたはボタンにクラスを追加したいですか?そのクラスを使用する( 'ui-button')あなたはホイールの再改良を避けるべきです... – gdoron

+0

私はすべてのテーブル、ボタン、標準look'n感じの特定のCSSファイルを持っています...クラスbtnまたはプライマリまたは。 ..私のボタンで(どこでも)私は、プライマリの色を変更することができ、他のクールなもの。 – Bronzato

答えて

1

@Colinは、1つの答えを持っていたが、私は問題のダイアログに、より具体的だろうと思いました。 jQuery-UIにはwidgetメソッドがあり、ダイアログ自体で構成される要素を返します。あなたが探しているものを手に入れることができ、ui-buttonクラスを見つけると、これをカップリング:

$dialog.dialog('widget') // Grab widget (UI element) 
    .find('.ui-button') // Locate buttons within 
    .addClass('btn');  // hadd btn class to them 

EDIT:また、ここでの例です:あなたがソースを見てみる場合はhttp://jsfiddle.net/8WckB/

+0

それは魅力のように動作します。クリーン。どうもありがとうございました。 – Bronzato

1
// Configure dialog 
$dialog.dialog({ 
    modal: true, 
    closeOnEscape: true, 
    resizable: false, 
    buttons: dialogButtons, 
    open: function(e, ui) { 
     $(this).parents(".ui-dialog").find(".ui-dialog-buttonset"); // here is your 
                    // button container 
     $(this).parents(".ui-dialog").find(".ui-dialog-buttonset .ui-button").addClass("btn"); // whereas this would select 
                           // all buttons in button container 
     // you could even use the widget method 
     // $(this).dialog("widget").find(".ui-dialog-buttonset .ui-button") 
    } 
}); 
0

、メソッド_createButtonsjquery.ui.dialog.jsの場合、ボタンのテキストによってインデックスされたハッシュは、関数でなければプロパティのコレクションとして扱われます。だから、次のことができます。

はここ
var $dlg = $('#dlg').dialog({ 
    buttons: { 
     'firstButton': {    
      'click': function() { 
       $dlg.dialog('close'); 
      }, 
      'text' : 'OK',   
      'class': 'myclass' 
     }, 
     'Cancel': function(){ 
      $dlg.dialog('close'); 
     } 
    } 
}); 

ブラッドのフィドルのフォークはコードhttp://jsfiddle.net/uWnpy/

+0

ありがとうございます。知っておいてよかった。 – Bronzato

関連する問題