2012-07-13 106 views
0

任何人都知道dijit.MenuItem標籤的自定義CSS選擇器?dijit.menu css選擇器

下面是增加了dijit.MenuItem的js的:

dojo.forEach(basemapGallery.basemaps, function(basemap) { 
     //Add a menu item for each basemap 
     dijit.byId("bingMenu").addChild(new dijit.MenuItem({ 
      label: basemap.title, 
      iconClass: basemap.title, 
      onClick: function(){basemapGallery.select(basemap.id)} 
     })); 
}); 

這裏的靜態html:

<td align="center" style="width: 50px;" valign="middle"> 
     <button id="dropdownButton" iconClass="btnImgBaseMap" title="Switch Basemap" dojoType="dijit.form.DropDownButton">      
      <div dojoType="dijit.Menu" id="bingMenu"> 
       <!--The menu items are dynamically created using the basemap gallery layers--> 
      </div> 
     </button> 
</td> 

謝謝!

回答

2

添加自定義CSS類菜單

var w = dijit.byId("bingMenu"); 
dojo.addClass(w.domNode, "myMenu"); 

,並使用下面的CSS

.dijitMenu.myMenu .dijitMenuItem .dijitMenuItemLabel { 
    color: white; 
} 

下面是一個例子:

http://jsfiddle.net/cswing/GCBnF/

如果你需要的CSS是每個菜單項都是唯一的,然後將自定義類添加到菜單項

var bingMenu = dijit.byId(...); 
var w = new dijit.MenuItem({ 
     label: basemap.title, 
     iconClass: basemap.title, 
     onClick: function(){basemapGallery.select(basemap.id)} 
    }); 
dojo.addClass(w.domNode, "bing"); 
bingMenu.addChild(w); 

,並使用下面的CSS

.dijitMenu.myMenu .dijitMenuItem.bing .dijitMenuItemLabel { 
    color: white; 
} 
+0

正是我一直在尋找。謝謝! – dan 2012-07-19 19:18:30