I can’t figure out how to add an onclick event to a menu item, please help me solve this problem.
<script>
require([
"dijit/MenuBar",
"dijit/PopupMenuBarItem",
"dijit/Menu",
"dijit/MenuItem",
"dijit/DropDownMenu",
"dojo/domReady!"
], function(MenuBar, PopupMenuBarItem, Menu, MenuItem, DropDownMenu){
var pMenuBar = new MenuBar({});
var pSubMenu = new DropDownMenu({});
pMenuBar.addChild(new PopupMenuBarItem({
label: "ItemMenu1",
popup: pSubMenu
}));
var pSubMenu2 = new DropDownMenu({});
pMenuBar.addChild(new PopupMenuBarItem({
label: "ItemMenu2",
popup: pSubMenu2,
}));
pMenuBar.placeAt("navigation");
pMenuBar.startup();
});
</script>
I added onClick to the code using this method, but it doesn’t work.
var pSubMenu = new DropDownMenu({});
pMenuBar.addChild(new PopupMenuBarItem({
label: "ItemMenu1",
popup: pSubMenu,
onClick: function () {alert('ItemMenu1');}
}));