2012-04-10 56 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