EasyUI Forum
April 19, 2024, 11:30:54 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Problem with menu appendItem  (Read 20447 times)
mickypc
Newbie
*
Posts: 1


View Profile
« on: July 06, 2011, 07:26:04 AM »

Code:
<script>
var arrs = ["test1","test1","test1","test1"];
for (var i=0;i<arrs.length;i++) {
  $("#div_menu").menu({
     text:arrs[i],
     onclick:function() {alert("ok")}
  });
}
</script>
<div id="div_menu" style="width:100px;"></div>

with this code, I want to alert "ok" by clicking the menu.but i just get wrong:the alert function just fires once when the menu initialized,bu no function by clicking the menu.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 06, 2011, 06:40:37 PM »

Create the menu first and then call 'appendItem' method to append menu item to your menu.

The easiest way to create menu is to add 'easyui-menu' class attribute to a <div/> markup, just like this:
<div id="div_menu" class="easyui-menu" style="width:100px;"></div>

Now you can call the 'appendItem' method:
Code:
var arrs = ["test1","test1","test1","test1"];
for (var i=0;i<arrs.length;i++) {
  $("#div_menu").menu('appendItem', {
     text:arrs[i],
     onclick:'javascript:alert("ok")'
     // or
     // handler:function() {alert("ok")}
  });
}

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!