EasyUI Forum
May 21, 2024, 04:19:18 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: catching click in menubuttons  (Read 9237 times)
jpierce
Jr. Member
**
Posts: 73


View Profile
« on: May 13, 2013, 02:02:07 PM »

How are you supposed to catch clicks on menubutton items?  Are you supposed to manually bind handlers to each of the individual menu items?  I was hoping to just bind one at the menubutton level (this is for a list of new tabs, so when you click on one it creates a tab for it).
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 14, 2013, 12:35:30 AM »

When click on a menubutton item, the 'onClick' event fires, in which you will be able to catch what item is clicked.
Code:
	<a href="#" class="easyui-menubutton" data-options="menu:'#mm',iconCls:'icon-help'">Help</a>
<div id="mm" style="width:100px;" data-options="
onClick:function(item){
alert(item.name);
}
">
<div data-options="name:'help'">Help</div>
<div data-options="name:'update'">Update</div>
<div data-options="name:'about'">About</div>
</div>
Logged
jpierce
Jr. Member
**
Posts: 73


View Profile
« Reply #2 on: May 14, 2013, 10:24:02 AM »

Ah, okay.  The onClick has to be set on the div following the anchor element.  That wasn't shown at all in the help/demo and wasn't obvious to me.  Thanks for the tip.

Also, is there any way it can be set after the fact using javascript?  I tried the following but it appeared to never hook any click events:
Code:
$('.easyui-menubutton').menubutton({
  onClick:function(item){
    alert(item.name);
  }
});
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: May 14, 2013, 10:48:36 AM »

Try the code:
Code:
var m = $('#mb').menubutton('options').menu;  // get the menu
$(m).menu({
onClick:function(item){
alert(item.name)
}
});
Logged
jpierce
Jr. Member
**
Posts: 73


View Profile
« Reply #4 on: May 14, 2013, 10:50:06 AM »

Okay, thanks!

Would be great for some of this to be added to the docs when there's some time.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!