2012-02-06 10 views
2

jQueryのUIダイアログを学習するために、以下に定義されているコードがあります。jQuery UIのカスタマイズダイアログ

私は3つのタスク

1を次の操作を行う必要がある

)ダイアログの右上端の閉じるボタンとしての私のカスタムイメージを使用して「OK」ボタンと「キャンセル」ボタン

2)としての私のイメージを使用ダイアログ全体の

3)背景には、OKボタンのタイトル、および場所を含む(「グレー」でなければなりません。)

重要な点は、スタイルは私のダイアログにのみ適用されるべきです。他のすべてのウィジェットにはデフォルトの動作が必要です。コンテンツエリアについては、#myDiv.ui-widget-contentを使用して達成することができました。

コードを教えてください。

注:可能な場合は、ベストプラクティスを使用してください。 (例:1.使用変数$ myDialog 2.使用AutoOpenプロパティはfalse)

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head id="Head1" runat="server"> 
    <title> </title> 

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.js"></script> 

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.6/jquery-ui.js"></script> 


<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.13/themes/redmond/jquery-ui.css" rel="stylesheet" 
     type="text/css" /> 


    <link href="Styles/OverrideMyDialog.css" rel="stylesheet" 
     type="text/css" />- 



<script type="text/javascript"> 

    $(document).ready(function() { 
     var $myDialog = $(".addNewDiv").dialog(
            { 
             autoOpen: false, 
             title: 'My Title', 
             buttons: { "OK": function() { 
              $(this).dialog("close"); 
              ShowAlert(); 
              return true; 
             }, 
              "Cancel": function() { 
               $(this).dialog("close"); 
               return false; 
              } 
             } 

            } 
              ); 





     $('#myOpener').click(function() { 
      return $myDialog.dialog('open'); 


     }); 
    }); 

    function ShowAlert() { 
     alert('OK Pressed'); 
    } 

</script> 

<body> 
    <div> 
    <input id="myOpener" type="button" value="button" /> 
</div> 
<div class="addNewDiv" id="myDiv" title="Add new Person" > 
    <table> 
     <tr> 
      <td> 
       Name 
      </td> 

     </tr> 
     <tr> 
      <td> 
       Age 
      </td> 

     </tr> 
    </table> 
</div> 
</body> 
</html> 

はまた、私は私のダイアログ

/* 
    *File Name: OverrideMyDialog.css 
    * jQuery UI CSS is overriden here for one div 
    */ 


/* Component containers 
----------------------------------*/ 

#myDiv.ui-widget-content 
{ 
border: 5px solid Red; 
background: Gray url(images/ui-bg_inset-hard_100_fcfdfd_1x100.png) 50% bottom repeat-x; 
color: Green; 
} 
のためのウィジェットの機能をオーバーライドするCSSクラスを作りました

答えて

4

私は上記の答えをupvotedしました。まだdialogClass: 'myDialogCSS'が私が探していた鍵でした。

HTMLとjQuery

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery- 
    1.4.4.js"></script> 
    <script type="text/javascript" 
     src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.6/jquery-ui.js"></script> 
    <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.13/themes/Sunny/jqueryui. 
    css" 
     rel="stylesheet" type="text/css" /> 
    <link href="Styles/MyStyleSheet.css" 
     rel="stylesheet" type="text/css" /> 

    <script type="text/javascript"> 
     $(document).ready(function() { 
      var $myDialog = $(".addNewDiv").dialog(
      { 
       modal: true, 
       autoOpen: false, 
       dialogClass: 'myDialogCSS', 
       title: 'My Title', 
       closeOnEscape: false, 
       open: function(event, ui) 
       { 
        //Disable OK Button 
        $(".ui-dialog-buttonpane 
         button:contains('OK')").attr("disabled", true).addClass("ui-state-disabled"); 
       }, 
       buttons: { "OK": function() 
       { 
        $(this).dialog("close"); 
        ShowAlert(); 
        return true; 
       }, 
        "Cancel": function() 
        { 
         $(this).dialog("close"); 
         return false; 
        } 
       } 
      } 
      ); 
      $('#myOpener').click(function() 
      { 
       return $myDialog.dialog('open'); 
      }); 
     }); 
     function ShowAlert() { 
      alert('OK Pressed'); 
     } 
    </script> 
</head> 

<body> 
    <div> 
     <input id="myOpener" type="button" value="button" /> 
    </div> 
    <div class="addNewDiv" id="myDiv" title="Add new Person"> 
     <table> 
      <tr> 
       <td>Name 

       </td> 
      </tr> 
      <tr> 
       <td>Age 
       </td> 
      </tr> 
     </table> 
    </div> 
</body> 
</html> 

MyStyleSheet.css

/*Title Bar*/ 
    .myDialogCSS .ui-dialog-titlebar 
    { 
     /*Hide Title Bar*/ 
     /*display:none; */ 
    } 

    /*Content*/ 
    .myDialogCSS .ui-dialog-content 
    { 
     font-size:30px; 
    } 
1

cssファイルをカスタマイズする必要があります。クラスは以下のとおりです。このため

.ui-dialog { position: absolute; padding: .2em; width: 300px; overflow: hidden; } 
.ui-dialog .ui-dialog-titlebar { padding: .4em 1em; position: relative; } 
.ui-dialog .ui-dialog-title { float: left; margin: .1em 16px .1em 0; } 
.ui-dialog .ui-dialog-titlebar-close { position: absolute; right: .3em; top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height: 18px; } 
.ui-dialog .ui-dialog-titlebar-close span { display: block; margin: 1px; } 
.ui-dialog .ui-dialog-titlebar-close:hover, .ui-dialog .ui-dialog-titlebar-close:focus { padding: 0; } 
.ui-dialog .ui-dialog-content { position: relative; border: 0; padding: .5em 1em; background: none; overflow: auto; zoom: 1; } 
.ui-dialog .ui-dialog-buttonpane { text-align: left; border-width: 1px 0 0 0; background-image: none; margin: .5em 0 0 0; padding: .3em 1em .5em .4em; } 
.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { float: right; } 
.ui-dialog .ui-dialog-buttonpane button { margin: .5em .4em .5em 0; cursor: pointer; } 
.ui-dialog .ui-resizable-se { width: 14px; height: 14px; right: 3px; bottom: 3px; } 
.ui-draggable .ui-dialog-titlebar { cursor: move; } 
+0

あなたは(これを適用し、どのようにする場所など)のサンプルを提供していただけますか? – Lijo

+1

これはタブのもので、ダイアログではありません。 – Darthg8r

+0

jquery-ui.cssファイル – Yorgo

1

あなたはjQueryのUI(jquery.ui.theme.css)が提供する過乗っデフォルトCSSになります。

  1. 画像Okボタンの画像:.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default背景画像を変更する必要があります。
  2. 閉じるボタン:変更.ui-widget-header .ui-icon
  3. 背景:.ui-widget-contentバックグラウンドプロパティを変更します。

これはうまくいきます。

+0

http://jqueryui.com/themeroller/にアクセスして、テーマをカスタマイズすることができます。それをダウンロードして再生してください。私も同じことを学びました。 Firebug(FF)、開発者ツールF12(IE)、F12 Chromeを使用して、アイテムに適用されたCSSを表示できます。このツールのみを使用して、私は上記の要素を見つけました。これがうまくいきたいです。 –

+0

また、あなたが答えに満足すれば、それを受け入れてください。第二に、助けが必要な場合は、コメントを投稿してください。 –

+1

私の場合、theme.cssはこのクラス '.ui-state-default、.ui-widget-content .ui-state-default、.ui-widget-header .ui-state-default'を持っています。いくつかの値を持つ1つのプロパティ 'background'。この値を取り除き、この 'url(" images/yourimage.png ")repeat-x scroll 50%50%#0E6D38'のような独自のイメージを置いてください。テーマフォルダの 'images'フォルダに画像をコピーします。 theme.cssの中で、私が提供した用語を直接検索し、 'background'プロパティを変更します。 –