easyui常用组件

来源:互联网 发布:码云的独立域名 编辑:程序博客网 时间:2024/06/02 11:05

本文主要内容是介绍EasyUI的一些常用组件的使用,都是一些非常基础的知识,适合入门者学习,主要包括Base(基础)、Layout(布局)、菜单和按钮、表单、窗口、表格和树等的使用。要求完全掌握这些内容,学会查阅文档,了解开发基本思想。如果想进一步深入学习,可以直接去官网进行学习,查阅文档等http://www.jeasyui.com/。


一、简介


EasyUI是一种第三方组织开发的,开源的,功能强大的,基于jquery的插件库。 主要可以用于web的后台前端。jQuery EasyUI 提供易于使用的组件,它使 Web 开发人员能快速地在流行的 jQuery 核心和 HTML5 上建立程序页面。 这里介绍的都是一些基本组件,项目中需要将其装配起来,方可构建完整的web页面,EasyUI只是众多前端WEB组件之一。

作用:快速基于现成的组件创建自己的web页面。组件:指已经有第三方写好的,直接可以使用的功能界面,例如:form,layout,tree等。


二、开发步骤

1、先去官网下载相应的插件:

2、在myeclipse中新建一个web工程

3、在WebRoot目录下创建js和themes目录,导入官方文件

4、新建一个helloword.html的网页,并引入下列文件:

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <link rel="stylesheet" href="themes/default/easyui.css" type="text/css" />  
  2. <link rel="stylesheet" href="themes/icon.css" type="text/css" />  
  3.   
  4. <script type="text/javascript" src="js/jquery.min.js"></script>  
  5. <script type="text/javascript" src="js/jquery.easyui.min.js"></script>  
  6. <script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>  

文件引入的顺序不要错,那么到目前为止,开发的准备工作就已经完成了。

三、Base组件的使用


3.1 Pagination(分页)


使用$.fn.pagination.defaults重写默认值对象

.分页组件是一个比较常用的组件之一,我们可以有两种使用方式,一种是直接在标签上面添加相应的属性,另一种是通过js进行操作。

静态方式创建如下:

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div  
  2.         id="pagination"  
  3.         class="easyui-pagination"  
  4.         data-options="total:2000,pageSize:10"  
  5.         style="background:#efefef;border:1px solid #ccc;"  
  6.     >  
  7. </div>  
动态方式:
[javascript] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div id="pp" style="background:#efefef;border:1px solid #ccc;"></div>   
  2.   
  3. <script>  
  4.     $("#pp").pagination({  
  5.         "total":100,   //表示总记录数  
  6.         "pageSize":10,  //每页显示多少条记录  
  7.         "pageNumber":2,   //当前页号  
  8.         "pageList":[10,20],  //  
  9.         "buttons":[  
  10.         {  
  11.             iconCls:'icon-add',  
  12.             handler:function(){alert('add')}  
  13.         },'-',{  
  14.             iconCls:'icon-save',  
  15.             handler:function(){alert('save')  
  16.             }  
  17.         }],  
  18.         "layout":['list','sep','first','prev','manual','next','last','links'],  
  19.         "showPageList":false,  
  20.   
  21.     });  
  22.   
  23.     $("#pp").pagination({  
  24.         "onSelectPage":function(pageNumber,b){  
  25.             alert(pageNumber);  
  26.             alert(b)  
  27.         }  
  28.     })  


我这里是添加了一些事件和方法的,可以依据实际情况进行增加或删除或修改里面的小的部分组件。大大方便了我们的开发。


3.2 ProgressBar(进度条)

使用$.fn.progressbar.defaults重写默认值对象。


使用HTML标签或程序创建进度条组件。从标签创建更加简单,添加'easyui-progressbar'类ID到<div/>标签。
[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div id="p" class="easyui-progressbar" data-options="value:60" style="width:400px;"></div>   

使用Javascript创建进度条。
[javascript] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div id="p"  style="width:400px;"  ></div><br />  
  2. <input id="startID" type="button"  value="开始"  style="width:100px;height:30px" />  
  3.       
  4.       
  5.       
  6.     <script>  
  7.         $("#p").progressbar({  
  8.             width:1000,  
  9.             height:40,  
  10.             value:0  
  11.         });  
  12.       
  13.         //获取1-9之间的随机数  
  14.         function getNum(){  
  15.             return Math.floor(Math.random()*9)+1;  
  16.         }  
  17.           
  18.         /* for(var i=0;i<20;i++){ 
  19.             var num=getNum(); 
  20.             document.write(num+"<br />"); 
  21.         } */  
  22.         var timeID=null;  
  23.         function update(){  
  24.             //获取随机值  
  25.               
  26.             var num=getNum();  
  27.             //获取进度条当前值  
  28.             var value=$("#p").progressbar("getValue");  
  29.             if(value+num>100){  
  30.                 //设置进度条当前值为100,且停止运行  
  31.                 $("#p").progressbar("setValue",100);  
  32.                 window.clearInterval(timeID);  
  33.                 $("#startID").removeAttr("disabled");  
  34.             }else{  
  35.                 $("#p").progressbar("setValue",(value+num))  
  36.             }  
  37.         }  
  38.           
  39.           
  40.         $("#startID").click(function(){  
  41.             timeID=window.setInterval("update()",500);  
  42.             //按钮失效  
  43.             $(this).attr("disabled","disabled");  
  44.         });  
  45.           
  46.       
  47.     </script>  




四、Layout组件的使用


4.1 layout的使用


布局是最常用的组件了,官方提供的是拥有5个布局方向的:北、南、东、西、中.

基本的使用方式如下:

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div    
  2.             id="layoutID"   
  3.             class="easyui-layout"  
  4.             data-options="fit:true"  
  5.             style="width:800px;height:500px">  
  6.               
  7.               
  8.         <!-- 上 -->  
  9.         <div data-options="region:'north',title:'上',split:true,iconCls:'icon-edit',minHeight:'100',maxHeight:'200'" style="height:100px;"></div>     
  10.           
  11.         <!-- 下 -->  
  12.         <div data-options="region:'south',title:'South Title',split:true" style="height:100px;"></div>     
  13.          
  14.         <!-- 右 -->  
  15.         <div data-options="region:'east',iconCls:'icon-reload',title:'East',split:true" style="width:100px;"></div>     
  16.         <!-- 左 -->  
  17.         <div data-options="region:'west',title:'West',split:true" style="width:200px;"></div>     
  18.         <!-- 中 -->  
  19.           
  20.         <div data-options="region:'center',title:'center title' " style="padding:5px;background:#eee;"></div>     
  21.           
  22.           
  23.           
  24.         </div>  

我们可以为其添加js的属性:
[javascript] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <script>  
  2.           
  3.         $(function(){  
  4.               
  5.             $('#layoutID').layout('collapse','north');  
  6.             //休息3秒  
  7.             window.setTimeout(function(){  
  8.                 //将南边折叠  
  9.                 $('#layoutID').layout("collapse","south");  
  10.                 //将北边展开  
  11.                 $('#layoutID').layout('expand','north');  
  12.                   
  13.                 //将南边展开  
  14.                 window.setTimeout(function(){  
  15.                     $("#layoutID").layout("expand","south");  
  16.                 },3000);  
  17.             },3000);  
  18.         });  
  19.           
  20.   
  21.         </script>  


对于布局来说,当然也还是可以进行嵌套处理的,我们可以摘除掉我们不需要的部分,然后将需要的部分进行再次组装。

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div id="layoutID"  class="easyui-layout"  data-options="fit:true" >  
  2.          <div data-options="region:'north',border:false" style="height:100px"></div>     
  3.           
  4.          <div data-options="region:'center'">   
  5.             <div  class="easyui-layout"  data-options="fit:true"  >  
  6.               
  7.                 <div data-options="region:'west',border:false" style="width:180px"></div>     
  8.                 <div data-options="region:'center'">  
  9.                   
  10.                     <div class="easyui-layout"  data-options="fit:true">  
  11.                           
  12.                              <div data-options="region:'north'" style="height:100px"></div>     
  13.                              <div data-options="region:'south'" ></div>     
  14.       
  15.                     </div>  
  16.                 </div>      
  17.             </div>  
  18.            </div>  
  19.           
  20.         </div>  


效果如下:

4.2 面板的使用

第一种方式:通过标签直接创建。
[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div    
  2.             id="panel"    
  3.             class="easyui-panel"   
  4.             title="我的第一个面板"  
  5.             data-options="iconCls:'icon-save',collapsible:'true',minimizable:true,maximizable:true"  
  6.               
  7.             style="width:800px;height:300px;padding:15px"  
  8.         >  
  9.             easyui入门  
  10.         </div>  

第二种方式:

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div id="p" style="padding:10px;">      
  2.     <p>panel content.</p>      
  3.     <p>panel content.</p>      
  4. </div>      
  5.      
[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <script>  
  2. $('#p').panel({      
  3.   width:500,      
  4.   height:150,      
  5.   title: 'My Panel',      
  6.   tools: [{      
  7.     iconCls:'icon-add',      
  8.     handler:function(){alert('new')}      
  9.   },{      
  10.     iconCls:'icon-save',      
  11.     handler:function(){alert('save')}      
  12.   }]      
  13. });     
  14.   
  15.     <div id="p" style="padding:10px;">  
  16.         <p>panel content.</p>  
  17.         <p>panel content.</p>  
  18.     </div>  
  19.       
  20.     $('#p').panel({  
  21.       width:500,  
  22.       height:150,  
  23.       title: 'My Panel',  
  24.       tools: [{  
  25.         iconCls:'icon-add',  
  26.         handler:function(){alert('new')}  
  27.       },{  
  28.         iconCls:'icon-save',  
  29.         handler:function(){alert('save')}  
  30.       }]  
  31.     });   
  32.  </script>  


4.3 Accordion(分类)

使用$.fn.accordion.defaults重写默认值对象。

分类空间允许用户使用多面板,但在同一时间只会显示一个。每个面板都内建支持展开和折叠功能。点击一个面板的标题将会展开或折叠面板主体。面板内容可以通过指定的'href'属性使用ajax方式读取面板内容。用户可以定义一个被默认选中的面板,如果未指定,那么第一个面板就是默认的。


[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div   
  2.     id="adID"   
  3.     class="easyui-accordion"   
  4.     data-options="fit:false,border:true,multiple:false,selected:-1"  
  5.       
  6.     style="width:300px;height:200px;"  
  7.     >  
  8.         <div title="北京" data-options="iconCls:'icon-save'"  
  9.             style="overflow:auto;padding:10px;">  
  10.             朝阳区  
  11.         </div>  
  12.         <div title="湖南" data-options="iconCls:'icon-reload'"  
  13.             style="padding:10px;">衡阳市  
  14.         </div>  
  15.         <div title="北京" data-options="iconCls:'icon-save'"  
  16.             style="overflow:auto;padding:10px;">  
  17.             <p>朝阳区</p>  
  18.         </div>  
  19.         <div title="湖南" data-options="iconCls:'icon-reload'"  
  20.             style="padding:10px;">  
  21.             <p>衡阳市</p>  
  22.             <p>长沙市</p>  
  23.         </div>  
  24.           
  25.     </div>  
  26.   
  27.   
  28.     <script>  
  29.         $(function(){  
  30.         //增加一个面版  
  31.             $("#adID").accordion("add",{  
  32.                 "title":"广东省",  
  33.                 "iconCls":"icon-add",  
  34.                 "content":"广州",  
  35.                 "selected":false  
  36.             });  
  37.             window.setTimeout(function(){  
  38.                 $("#adID").accordion("remove","北京");  
  39.                 $("#adID").accordion("unselect",0);  
  40.                   
  41.             },3000);  
  42.       
  43.           
  44.         });  
  45.           
  46.       
  47.       
  48.     </script>  


4.4 Tabs(选项卡)


使用$.fn.tabs.defaults重写默认值对象。

选项卡显示一批面板。但在同一个时间只会显示一个面板。每个选项卡面板都有头标题和一些小的按钮工具菜单,包括关闭按钮和其他自定义按钮。


[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div   
  2.     id="tt"   
  3.     class="easyui-tabs"   
  4.     data-options="plain:false,fit:false,border:true,tools:[  
  5.         {  
  6.             iconCls:'icon-add',  
  7.             handler:function(){  
  8.                 alert('添加')  
  9.             }  
  10.           
  11.         },  
  12.         {  
  13.             iconCls:'icon-sava',  
  14.             handler:function(){  
  15.                 alert('保存')  
  16.             }  
  17.         }  
  18.     ],toolPosition:'right',tabPosition:'top',selected:2"  
  19.       
  20.       
  21.     style="width:500px;height:250px;"  
  22.       
  23.     >  
  24.         <div title="Tab1" style="padding:20px;display:none;">tab1</div>  
  25.         <div title="Tab2" data-options="closable:true"  
  26.             style="overflow:auto;padding:20px;display:none;">tab2</div>  
  27.         <div title="Tab3" data-options="iconCls:'icon-reload',closable:true"  
  28.             style="padding:20px;display:none;">tab3</div>  
  29.     </div>  




五、Menu 和Button组件的使用

LinkButton(按钮)

使用$.fn.linkbutton.defaults重写默认值对象。

按钮组件使用超链接按钮创建。它使用一个普通的<a>标签进行展示。它可以同时显示一个图标和文本,或只有图标或文字。按钮的宽度可以动态和折叠/展开以适应它的文本标签。

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <a id="btn_add" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',group:'sex',toggle:true,iconAlign:'right'">增加部门</a><br />  
  2.    <a id="btn_find" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search',group:'sex',toggle:true"">查找部门</a><br />  
  3.       
  4.     <a id="btn_update" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',group:'sex',toggle:true"">修改部门</a><br />  
  5.     <a id="btn_delete" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',group:'sex',toggle:true"">删除部门</a><br />  
  6.        
  7.           
  8.     <script>  
  9.         $("a").click(function(){  
  10.             //获取单击的按钮的标题  
  11.             var title=$(this).text();  
  12.             //去空格  
  13.             title=$.trim(title);  
  14.             alert(title);  
  15.           
  16.         });  
  17.     </script>   




六、Form组件的使用


6.1 ValidateBox(验证框)

使用$.fn.validatebox.defaults重写默认值对象。

validatebox(验证框)的设计目的是为了验证输入的表单字段是否有效。如果用户输入了无效的值,它将会更改输入框的背景颜色,并且显示警告图标和提示信息。该验证框可以结合form(表单)插件并防止表单重复提交。  

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. 姓名:<input id="nameID"  /><br />  
  2.     邮箱:<input id="emailID"  /><br />  
  3.     密码:<input id="pwdID"  />  
  4.       
  5.     <script>  
  6.         $("#nameID").validatebox({  
  7.             required:true,  
  8.             //validType:'length[1,6]'  
  9.             validType:['length[1,6]','chinese'],  
  10.             delay:200,  
  11.             tipPosition:'left'  
  12.           
  13.         });  
  14.         //自定义规则,验证是否为汉字  
  15.         $.extend($.fn.validatebox.defaults.rules,{  
  16.             chinese:{  
  17.                 //validator表示用户在文本框中输入的内容  
  18.                 validator:function(value){  
  19.                     var reg=/^[\u4e00-\u9fa5]/;  
  20.                     if(reg.test(value)){  
  21.                         return true;  
  22.                     }  
  23.                 },  
  24.                 //如果不符合中文规则,  
  25.                 message:'姓名必须是中文'  
  26.             }  
  27.           
  28.           
  29.         });  
  30.           
  31.         $("#emailID").validatebox({  
  32.             required:true,  
  33.             validType: ['length[1,30]','email']  
  34.           
  35.         });  
  36.           
  37.         $("#pwdID").validatebox({  
  38.             required:true,  
  39.             validType: ['length[6,6]','pwdnum']  
  40.           
  41.         });  
  42.             //自定义规则,验证是否为密码  
  43.         $.extend($.fn.validatebox.defaults.rules,{  
  44.             pwdnum:{  
  45.                 //validator表示用户在文本框中输入的内容  
  46.                 validator:function(value){  
  47.                     var reg=/^[0-9]/;  
  48.                     if(reg.test(value)){  
  49.                         return true;  
  50.                     }  
  51.                 },  
  52.                 //如果不符合中文规则,  
  53.                 message:'密码必须为数字'  
  54.             }  
  55.         });  
  56.           
  57.       
  58.     </script>  
对于表单验证,我们可以对其进行自定义规则。这个时候如果加上正则验证,就完全可以写出一个非常好的验证功能的了。在上面的这个属性中,还可以对提示框的位置进行改变,可以使用的属性是left和right。下面图片中显示的就是一个提示框在left的情况,一般情况下使用默认的right就可以了。




6.2 ComboBox(下拉列表框)


扩展自$.fn.combo.defaults。使用$.fn.combobox.defaults重写默认值对象。

下拉列表框显示一个可编辑文本框和下拉式列表,用户可以选择一个值或多个值。用户可以直接输入文本到列表顶部或选择一个或多个当前列表中的值。

静态方法创建:

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <select id="cc" class="easyui-combobox" name="dept" style="width:200px;">     
  2.             <option value="aa">aitem1</option>     
  3.             <option>bitem2</option>     
  4.             <option>bitem3</option>     
  5.             <option>ditem4</option>     
  6.             <option>eitem5</option>     
  7.         </select>   

动态方法创建:
[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <input  id="cityID"  name="city"  value="1"/>  
  2.         <script>  
  3.             $("#cityID").combobox({  
  4.                 url:"json/city.json",  
  5.                 valueField:"id",  
  6.                 textField:"name"  
  7.             });  
  8.           
  9.           
  10.             $(function(){  
  11.                 $("#cityID").comcobox("setValue","长沙");  
  12.                   
  13.             });  
  14.           
  15.         </script>  


6.3 DateBox(日期输入框)

扩展自$.fn.combo.defaults。使用$.fn.datebox.defaults重写默认值对象。

日期输入框结合了一个可编辑的文本框控件和允许用户选择日期的下拉日历面板控件。选择的日期会自动转变为一个有效的日期然后填充到文本框中。选定的日期也可以被格式化为预定格式。


[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. 日期:  
  2.     <input id="dd" type="text"></input>    
  3.   
  4.   
  5.    
  6.         <script>  
  7.         $('#dd').datebox({      
  8.             required:true     
  9.         });  
  10.           
  11.           
  12.         $("#dd").datebox({  
  13.             onSelect:function(mydate){  
  14.               
  15.                 var year=mydate.getFullYear();  
  16.                 var month=mydate.getMonth()+1;  
  17.                 var date=mydate.getDate();  
  18.               
  19.                 alert(year+"年"+month+"月"+date+"日");  
  20.             }  
  21.           
  22.         });  
  23.           
  24.           
  25.         </script>  



6.4 Slider(滑动条)

使用$.fn.slider.defaults重写默认值对象。

滑动条允许用户从一个有限的范围内选择一个数值。当滑块控件沿着轨道移动的时候,将会显示一个提示来表示当前值。用户可以通过设置其属性自定义滑块。

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. 学生成绩:<span id="tip" ></span>  
  2.     <hr />  
  3.     <div  id="ss"  style="height:400px;width:400px">  
  4.     </div>  
  5.   
  6.   
  7.     <script>  
  8.         $("#ss").slider({  
  9.             mode:"h",  
  10.             min:0,  
  11.             max:100,  
  12.             rule:[0,'|',25,'|',50,'|',75,'|',100],  
  13.             showTip:true,  
  14.             value:60  
  15.         });  
  16.       
  17.         $("#ss").slider({  
  18.             onChange:function(newValue){  
  19.                 if(newValue==60){  
  20.                     $("#tip").text("合格").css("color","yellow");  
  21.                 }else if(newValue==70){  
  22.                     $("#tip").text("中等").css("color","pink");  
  23.                 }else if(newValue==80){  
  24.                     $("#tip").text("良好").css("color","blue");  
  25.                 }else if(newValue==90){  
  26.                     $("#tip").text("优秀").css("color","green");  
  27.                 }  
  28.             }  
  29.         })  
  30.       
  31.       
  32.     </script>  


6.5 NumberSpinner(数字微调)

数字微调控件的创建是基于微调控件和数值输入框控件的。他可以转换输入的值,比如:数值、百分比、货币等。它也允许使用上/下微调按钮调整到用户的期望值。


[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. 商品数量:  
  2. <input id="ss" style="width:100px">  <br />    
  3.   
  4.     你一共买了<span id="num">1</span>件商品  
  5.     <script>  
  6.     $('#ss').numberspinner({      
  7.       value:1,  
  8.         min:1,  
  9.         max:100     
  10.     });    
  11.           
  12.     $('#ss').numberspinner({  
  13.         onSpinUp:function(){  
  14.             var value=$("#ss").numberspinner("getValue");  
  15.             //将当前值设置到span标签  
  16.             $("#num").text(value).css("color","red");  
  17.         },  
  18.         onSpinDown:function(){  
  19.             var value=$("#ss").numberspinner("getValue");  
  20.             //将当前值设置到span标签  
  21.             $("#num").text(value).css("color","red");  
  22.         }  
  23.   
  24.     });       
  25.           
  26.           
  27.         //添加键盘事件  
  28.         $('#ss').keyup(function(event){  
  29.             //获取按键的unicode编码  
  30.             var myevent=event;  
  31.             var code=myevent.keyCode;  
  32.             if(code==13){  
  33.                 var value=$(this).val();  
  34.                 //将当前值设置到span标签  
  35.                 $("#num").text(value).css("color","red");  
  36.             }  
  37.         });  
  38.           
  39.     </script>  



七、窗口组件的使用

7.1 Window(窗口)

扩展自$.fn.panel.defaults。使用$.fn.window.defaults重写默认值对象。

窗口控件是一个浮动和可拖拽的面板可以用作应用程序窗口。默认情况下,窗口可以移动,调整大小和关闭。它的内容也可以被定义为静态html或要么通过ajax动态加载。

静态方法创建:
[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <div id="win" class="easyui-window" title="My Window" style="width:600px;height:400px"     
  2.         data-options="iconCls:'icon-save',modal:true">     
  3.     Window Content      
  4.     </div>    
动态创建:
[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <input type="button"  value="打开窗口1"  id="open1"/>  
  2.     <input type="button"  value="打开窗口2"  id="open2"/>  
  3.       
  4.       
  5.     <div id="win1"></div>    
  6.     <div id="win2"></div>    
  7.   
  8.  <script>  
  9.    
  10.     $("#open1").click(function(){  
  11.          $('#win1').window({      
  12.             width:600,      
  13.             height:400,      
  14.             modal:false ,  
  15.             minimizable  :false,  
  16.             maximizable:false,  
  17.             title:"我的窗口"  
  18.         });  
  19.     });  
  20.       
  21.       
  22.     $("#open2").click(function(){  
  23.          $('#win2').window({      
  24.             width:600,      
  25.             height:400,      
  26.             modal:false ,  
  27.             minimizable  :false,  
  28.             maximizable:false,  
  29.             title:"我的窗口"  
  30.         });  
  31.     });  
  32.        
  33.    
  34.  </script>  



7.2  Dialog(对话框窗口)


该对话框是一种特殊类型的窗口,它在顶部有一个工具栏,在底部有一个按钮栏。对话框窗口右上角只有一个关闭按钮用户可以配置对话框的行为显示其他工具,如collapsible,minimizable,maximizable工具等。

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <input type="button"  value="打开对话框"  id="open1"/>  
  2.   
  3.     <div id="win1"></div>    
  4.       
  5.   
  6.  <script>  
  7.  $("#open1").click(function(){  
  8.          $('#win1').dialog({      
  9.             width:400,      
  10.             height:400,      
  11.             modal:false ,  
  12.             minimizable  :false,  
  13.             maximizable:false,  
  14.             title:"我的对话框",  
  15.             toolbar:[  
  16.                 {  
  17.                 text:'编辑',  
  18.                 iconCls:'icon-edit',  
  19.                 handler:function(){alert('edit')}  
  20.             },{  
  21.                 text:'帮助',  
  22.                 iconCls:'icon-help',  
  23.                 handler:function(){alert('help')}  
  24.             }  
  25.             ],  
  26.             buttons:[  
  27.             {  
  28.                 text:'保存',  
  29.                 handler:function(){alert("保存");}  
  30.             },{  
  31.                 text:'关闭',  
  32.                 handler:function(){  
  33.                     //关闭对话框  
  34.                     $("#win1").dialog("close");  
  35.                   
  36.                 }  
  37.             }  
  38.             ],  
  39.             href:"/EasyUi/form.html"   
  40.         });  
  41.     });  
  42.       
  43.    
  44.  </script>  


7.3  Messager(消息窗口)


消息窗口提供了不同的消息框风格,包含alert(警告框), confirm(确认框), prompt(提示框), progress(进度框)等。所有的消息框都是异步的。用户可以在交互消息之后使用回调函数去处理结果或做一些自己需要处理的事情。

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <input type="button"  value="确认框"  /><br />  
  2.     <input type="button"  value="警告框"  /><br />  
  3.     <input type="button"  value="输入框"  /><br />  
  4.     <input type="button"  value="显示框"  /><br />  
  5.       
  6.   
  7.     <script>  
  8.         $("input").click(function(){  
  9.           
  10.             //定位button按钮,提供单击事件  
  11.             var tip=$(this).val();  
  12.             tip=$.trim(tip);  
  13.             if("警告框"==tip){  
  14.                 $.messager.alert("警告框","警告处分","waring",function(){  
  15.                     //alert("关闭");  
  16.                 });  
  17.             }  
  18.               
  19.             if("确认框"==tip){  
  20.             $.messager.confirm("确认框","你确认要删除么",function(value){  
  21.                 alert(value);  
  22.             });  
  23.             }  
  24.               
  25.             if("输入框"==tip){  
  26.             $.messager.prompt("输入框","请输入你的姓名",function(name){  
  27.                 alert(name);  
  28.             });  
  29.             }  
  30.               
  31.             if("显示框"==tip){  
  32.             $.messager.show({  
  33.                 showType: "slide",  
  34.                 showSpeed: 600,  
  35.                 width:300,  
  36.                 height:300,  
  37.                 title:"显示框",  
  38.                 timeout:5000,  
  39.                 msg:'消息将在5秒后关闭。'  
  40.                   
  41.             }  
  42.               
  43.             );  
  44.             }  
  45.         });  
  46.       
  47.       
  48.       
  49.     </script>  




八、表格和树组件的使用

使用$.fn.tree.defaults重写默认值对象。

树控件在web页面中一个将分层数据以树形结构进行显示。它提供用户展开、折叠、拖拽、编辑和异步加载等功能。




[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <ul id="treeID" class="easyui-tree">     
  2.        <li>  
  3.             <span>第一章</span>  
  4.             <ul>  
  5.                 <li>  
  6.                     <span>第一节</span>  
  7.                     <ul>  
  8.                         <li>  
  9.                             <span>第一条</span>  
  10.                         </li>  
  11.                         <li>  
  12.                             <span>第二条</span>  
  13.                         </li>  
  14.                     </ul>  
  15.                 </li>  
  16.                 <li>  
  17.                     <span>第二节</span>  
  18.                 </li>  
  19.             </ul>      
  20.        </li>  
  21.        <li>  
  22.             <span>第二章</span>  
  23.        </li>  
  24.     </ul>    
  25.       
  26.       
  27.       
  28.     <script type="text/javascript">  
  29.         $(function(){  
  30.             //收起所有的选项  
  31.             $("#treeID").tree("collapseAll");  
  32.         });  
  33.     </script>  



我们还可以引入外部文件,使用json格式的文件来添加到这个tree中。

[html] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <ul id="treeID"></ul>  
  2.     <script type="text/javascript">  
  3.         $("#treeID").tree({  
  4.             url : "/EasyUi/json/pro.json"  
  5.         });  
  6.     </script>   

json格式为:
[plain] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. [  
  2.   {      
  3.     "id":1,      
  4.     "text":"广东",  
  5.     "state":"closed",  
  6.     "children":[  
  7.     {  
  8.        "id":11,  
  9.        "text":"广州"  ,  
  10.            "state":"closed",  
  11.            "children":[  
  12.           {  
  13.          "id":111,      
  14.                  "text":"天河"  
  15.           },      
  16.           {  
  17.          "id":112,      
  18.                  "text":"越秀"  
  19.           }   
  20.        ]  
  21.     },  
  22.     {  
  23.        "id":12,  
  24.        "text":"深圳"        
  25.     }  
  26.     ]  
  27.   },      
  28.   {      
  29.     "id":2,      
  30.     "text":"湖南"  
  31.   }   
  32. ]   

0 0
原创粉丝点击