2012-04-10 58 views
0

有人可以幫我添加一個類到ui-dialog-buttonset ..我有2個按鈕「添加」和「刪除」,並希望每個適當的樣式。addClass與ui-dialog按鈕的問題

我如何添加一個類,上面寫着 '添加此項目' 按鈕

$dialogContent.dialog({ 
      modal: true, 
      resizable: false, 
      title: "New thing", 
      close: function() { 
       $dialogContent.dialog("destroy"); 
       $dialogContent.hide(); 
       $('#other').stuff("removeUnsavedEvents"); 
      }, 

      buttons: { 
       'Add this item' : function() { 

        if(client_url.val() == '') 
        { 
         alert('client not selected'); 
         $other.stuff("removeUnsavedEvents"); 
         $dialogContent.dialog("close"); 
         return; 
        } 

          $dialogContent.dialog("close"); 
         }, 
        }); 

        update_stuff_overview(); 
       } 
      } 

     } 

感謝

編輯從UI的對話框插件添加HTML ..

<div class="ui-dialog-buttonset"> 
    <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"> 
     <span class="ui-button-text">Add this item</span> 
    </button> 
</div> 

我試圖在上面的按鈕中添加「new_class」。

+0

請張貼您在此頁面使用的所有HTML,JS。 – 2012-04-10 04:52:38

+0

沒有HTML去與此。僅此一點就是添加那個讀取'Add this item'的特定按鈕。 jquery ui-dialog函數自己添加按鈕。 – Josh 2012-04-10 05:00:00

回答

0

下面是答案

var button_text = $('#button-id').attr('value'); 
if(button_text == 'Add this item'){ 
    $('#button-id').addClass('class_name'); 
} 
+0

不是答案。這就是ui-dialog插件放入html的內容,我在上面編輯了我的問題* – Josh 2012-04-10 21:37:01

0

在對話框的open事件補充一點:

$(this).parent().find('button:nth-child(1)').addClass('your-class-name'); 

它只會樣式的第一個按鈕。如果您想要設置其他按鈕的樣式,請以相同的方式應用,但更改兒童編號(例如'button:nth-​​child(2)')。這是我的樣式我的按鈕jQuery 1.9