当前位置:编程学习 > JAVA >>

easyUI menu动态添加

HTML代码:

[html] <!-- 菜单 --> 
          <div id="mm" class="easyui-menu" style="width:140px;">   
       
            </div>   
<!-- 菜单 -->
       <div id="mm" class="easyui-menu" style="width:140px;"> 
     
            </div> 


Javascript代码:

[javascript] /*绑定右键*/ 
                 $(".datagrid-cell").live('contextmenu',function(e){//.datagrid-cell 是easyUI表格样式,这样设置的原因是,让菜单在表格上点击右键才显示  
                  var selectRow=$('#grid').datagrid('getSelected');//获得选中行数据  
                     //显示快捷菜单  
                     if(selectRow==null){ 
                      Ext.Msg.alert('提示', '请在表格上单击左键选择一行数据.'); 
                      return false; 
                     } 
                     //第一步将集合清空  
                     $('#mm').empty(); 
                     //创建菜单  
                     createMenu(selectRow); 
                    // alert($('#mm').children().size());  
                     //没有子菜单,那么不显示  
                     if($('#mm').children().size()==0){ 
                         return false; 
                     } 
                   //菜单添加完毕显示菜单  
                     $('#mm').menu('show', { 
                         left: e.pageX, 
                         top: e.pageY 
                     }); 
                     return false; 
                 }); 
/*绑定右键*/
                 $(".datagrid-cell").live('contextmenu',function(e){//.datagrid-cell 是easyUI表格样式,这样设置的原因是,让菜单在表格上点击右键才显示
                  var selectRow=$('#grid').datagrid('getSelected');//获得选中行数据
                     //显示快捷菜单
                     if(selectRow==null){
                      Ext.Msg.alert('提示', '请在表格上单击左键选择一行数据.');
                      return false;
                     }
                     //第一步将集合清空
                     $('#mm').empty();
                     //创建菜单
                     createMenu(selectRow);
                    // alert($('#mm').children().size());
                     //没有子菜单,那么不显示
                     if($('#mm').children().size()==0){
                      return false;
                     }
                   //菜单添加完毕显示菜单
                     $('#mm').menu('show', {
                         left: e.pageX,
                         top: e.pageY
                     });
                    

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,