dijit.menu css选择器

时间:2012-07-13 14:10:05

标签: dojo

任何人都知道dijit.MenuItem标签的自定义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>

谢谢!

1 个答案:

答案 0 :(得分: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;   
}