EasyUI笔记(一)Layout布局

Panel(面板)

1. 通过标签创建面板

  1. <div id="p" class="easyui-panel" title="My Panel"
  2. style="width:500px;height:150px;padding:10px;background:#fafafa;"
  3. data-options="iconCls:‘icon-save‘,closable:true,
  4. collapsible:true,minimizable:true,maximizable:true">
  5. <p>panel content.</p>
  6. <p>panel content.</p>
  7. </div>

2. 创建面板程序

  1. <div id="p" style="padding:10px;">
  2. <p>panel content.</p>
  3. <p>panel content.</p>
  4. </div>
  5. $(‘#p‘).panel({
  6. width:500,
  7. height:150,
  8. title: ‘My Panel‘,
  9. tools: [{
  10. iconCls:‘icon-add‘,
  11. handler:function(){alert(‘new‘)}
  12. },{
  13. iconCls:‘icon-save‘,
  14. handler:function(){alert(‘save‘)}
  15. }]
  16. });

属性

属性名 属性值类型 描述 默认值
id string 面板的ID属性。 null
title string 在面板头部显示的标题文本。 null
iconCls string 设置一个16x16图标的CSS类ID显示在面板左上角。 null
width number 设置面板宽度。 auto
height number 设置面板高度。 auto
left number 设置面板距离左边的位置(即X轴位置)。 null
top number 设置面板距离顶部的位置(即Y轴位置)。 null
cls string 添加一个CSS类ID到面板。 null
headerCls string 添加一个CSS类ID到面板头部。 null
bodyCls string 添加一个CSS类ID到面板正文部分。 null
style object 添加一个当前指定样式到面板。

如下代码示例更改面板边框宽度:

<div class="easyui-panel" style="width:200px;height:100px"
        data-options="style:{borderWidth:2}">
</div>
{}
fit boolean 当设置为true的时候面板大小将自适应父容器。下面的例子显示了一个面板,可以自动在父容器的最大范围内调整大小。

<div style="width:200px;height:100px;padding:5px">
	<div class="easyui-panel" style="width:200px;height:100px"
			data-options="fit:true,border:false">
		Embedded Panel
	</div>
</div>
false
border boolean 定义是否显示面板边框。 true
doSize boolean 如果设置为true,在面板被创建的时候将重置大小和重新布局。 true
noheader boolean 如果设置为true,那么将不会创建面板标题。 false
content string 面板主体内容。 null
collapsible boolean 定义是否显示可折叠按钮。 false
minimizable boolean 定义是否显示最小化按钮。 false
maximizable boolean 定义是否显示最大化按钮。 false
closable boolean 定义是否显示关闭按钮。 false
tools array,selector 自定义工具菜单,可用值:
1) 数组,每个元素都包含‘iconCls‘和‘handler‘属性。
2) 指向工具菜单的选择器。

面板工具菜单可以声明在已经存在的<div>标签上:

<div class="easyui-panel" style="width:300px;height:200px"
		title="My Panel" data-options="iconCls:‘icon-ok‘,tools:‘#tt‘">
</div>
<div id="tt">
	<a href="#" class="icon-add" onclick="javascript:alert(‘add‘)"></a>
	<a href="#" class="icon-edit" onclick="javascript:alert(‘edit‘)"></a>
</div>

面板工具菜单也可以通过数组定义:

<div class="easyui-panel" style="width:300px;height:200px"
		title="My Panel" data-options="iconCls:‘icon-ok‘,tools:[
				{
					iconCls:‘icon-add‘,
					handler:function(){alert(‘add‘)}
				},{
					iconCls:‘icon-edit‘,
					handler:function(){alert(‘edit‘)}
				}]">
</div>
[]
collapsed boolean 定义是否在初始化的时候折叠面板。 false
minimized boolean 定义是否在初始化的时候最小化面板。 false
maximized boolean 定义是否在初始化的时候最大化面板。 false
closed boolean 定义是否在初始化的时候关闭面板。 false
href string 从URL读取远程数据并且显示到面板。注意:内容将不会被载入,直到面板打开或扩大,在创建延迟加载面板时是非常有用的:

<div id="pp" class="easyui-panel" style="width:300px;height:200px"
		data-options="href=‘get_content.php‘,closed:true">
</div>
<a href="#" onclick="javascript:$(‘#pp‘).panel(‘open‘)">Open</a>
null
cache boolean 如果为true,在超链接载入时缓存面板内容。 true
loadingMessage string 在加载远程数据的时候在面板内显示一条消息。 Loading…
extractor function 定义如何从ajax应答数据中提取内容,返回提取数据。

extractor: function(data){
	var pattern = /<body[^>]*>((.|[\n\r])*)<\/body>/im;
	var matches = pattern.exec(data);
	if (matches){
		return matches[1];	// 仅提取主体内容
	} else {
		return data;
	}
}

Tabs(选项卡)

1. 通过标签创建选项卡

通过标签可以更容易的创建选项卡,我们不需要写任何Javascript代码。只需要给<div/>标签添加一个类ID‘easyui-tabs‘。每个选项卡面板都通过子<div/>标签进行创建,用法和panel(面板)相同。

  1. <div id="tt" class="easyui-tabs" style="width:500px;height:250px;">
  2. <div title="Tab1" style="padding:20px;display:none;">
  3. tab1
  4. </div>
  5. <div title="Tab2" data-options="closable:true" style="overflow:auto;padding:20px;display:none;">
  6. tab2
  7. </div>
  8. <div title="Tab3" data-options="iconCls:‘icon-reload‘,closable:true" style="padding:20px;display:none;">
  9. tab3
  10. </div>
  11. </div>

2. 通过Javascript创建选项卡

  1. $("#tabs-tt2").tabs({
  2. width:600,
  3. height:300,
  4. //plain:true,
  5. //fit:true,
  6. //border:false,
  7. //tabWidth:300,
  8. scrollncrement:200,
  9. scrollDuration:2000,
  10. tools:[{
  11. iconCls:‘icon-add‘,
  12. handler:function(){
  13. alert(‘添加‘)
  14. }
  15. },{
  16. iconCls:‘icon-cut‘,
  17. handler:function(){
  18. alert(‘裁剪‘)
  19. }
  20. }],
  21. toolPosition:‘right‘,
  22. //tabPosition:‘left‘,
  23. //headerWidth:200,
  24. //selected:2,
  25. onSelect:function(title,index){
  26. //alert(‘title:‘+title+‘;index:‘+index);
  27. },
  28. onContextMenu:function(e,title,index){
  29. alert(e.type);
  30. }
  31. });

属性

属性名 属性值类型 描述 默认值
width number 选项卡容器宽度。 auto
height number 选项卡容器高度。 auto
plain boolean 设置为true时,将不显示控制面板背景。 false
fit boolean 设置为true时,选项卡的大小将铺满它所在的容器。 false
border boolean 设置为true时,显示选项卡容器边框。 true
scrollIncrement number 选项卡滚动条每次滚动的像素值。 100
scrollDuration number 每次滚动动画持续的时间,单位:毫秒。 400
tools array,selector 工具栏添加在选项卡面板头的左侧或右侧。可用的值有:
1. 一个工具菜单数组,每个工具选项都和linkbutton相同。
2.
一个指向<div/>容器工具菜单的选择器。

代码示例:

通过数组定义工具菜单。

$(‘#tt‘).tabs({
	tools:[{
		iconCls:‘icon-add‘,
		handler:function(){
			alert(‘添加‘)
		}
	},{
		iconCls:‘icon-save‘,
		handler:function(){
			alert(‘保存‘)
		}
	}]
});

通过存在的DOM容器定义工具菜单。

$(‘#tt‘).tabs({
	tools:‘#tab-tools‘
});
<div id="tab-tools">
	<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-add"></a>
	<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-save"></a>
</div>
null
toolPosition string 工具栏位置。可用值:‘left‘,‘right‘。(该属性自1.3.2版开始可用) right
tabPosition string 选项卡位置。可用值:‘top‘,‘bottom‘,‘left‘,‘right‘。(该属性自1.3.2版开始可用) top
headerWidth number 选项卡标题宽度,在tabPosition属性设置为‘left‘或‘right‘的时候才有效。(该属性自1.3.2版开始可用) 150
tabWidth number 标签条的宽度。(该属性自1.3.4版开始可用) auto
tabHeight number 标签条的高度。(该属性自1.3.4版开始可用) 27
selected number 初始化选中一个tab页。(该属性自1.3.5版开始可用) 0
showHeader boolean 设置为true时,显示tab页标题。(该属性自1.3.5版开始可用) true

选项卡面板

选项卡面板属性与panel组件属性的定义类似,下面是2个组件的一些公共属性。

属性名 属性值类型 描述 默认值
id string 选项卡面板的ID属性。 null
title string 选项卡面板的标题文本。
content string 选项卡面板的内容。
href string 从URL加载远程数据内容填充到选项卡面板。 null
cache boolean 如果为true,在‘href‘属性设置了有效值的时候缓存选项卡面板。 true
iconCls string 定义了一个图标的CSS类ID显示到选项卡面板标题。 null
width number 选项卡面板宽度。 auto
height number 选项卡面板高度。 auto
collapsible boolean 如果为true,则允许选项卡摺叠。 false

下面的是选项卡面板新增且独有的属性。

属性名 属性值类型 描述 默认值
closable boolean 在设置为true的时候,选项卡面板将显示一个关闭按钮,在点击的时候会关闭选项卡面板。 false
selected boolean 在设置为true的时候,选项卡面板会被选中。 false

添加新面板

  1. $("#tabs-tt2").tabs(‘add‘,{
  2. id:‘ddd‘,
  3. title:‘新的面板‘,
  4. href:‘test.php‘,
  5. iconCls:‘icon-add‘,
  6. closable:true,
  7. });

Accordion(分类)

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

通过标签创建分类,给<div/>标签添加一个名为‘easyui-accordion‘的类ID。

  1. <div id="aa" class="easyui-accordion" style="width:300px;height:200px;">
  2. <div title="Title1" data-options="iconCls:‘icon-save‘" style="overflow:auto;padding:10px;">
  3. <h3 style="color:#0099FF;">Accordion for jQuery</h3>
  4. <p>Accordion is a part of easyui framework for jQuery.
  5. It lets you define your accordion component on web page more easily.</p>
  6. </div>
  7. <div title="Title2" data-options="iconCls:‘icon-reload‘,selected:true" style="padding:10px;">
  8. content2
  9. </div>
  10. <div title="Title3">
  11. content3
  12. </div>
  13. </div>

容器属性

属性名 属性值类型 描述 默认值
width number 分类容器的宽度。 auto
height number 分类容器的高度。 auto
fit boolean 如果设置为true,分类容器大小将自适应父容器。 false
border boolean 定义是否显示边框。 true
animate boolean 定义在展开和折叠的时候是否显示动画效果。 true
multiple boolean 如果为true时,同时展开多个面板。(该属性自1.3.5版开始可用) false
selected number 设置初始化时默认选中的面板索引号。(该属性自1.3.5版开始可用) 0

面板属性

分类面板属性继承自panel(面板),分类面板新增的属性如下:

属性名 属性值类型 描述 默认值
selected boolean 如果设置为true将展开面板。 false
collapsible boolean 如果设置为true将显示折叠按钮。 true

Layout(布局)

布局容器有5个区域:北、南、东、西和中间。中间区域面板是必须的,边缘的面板都是可选的。每个边缘区域面板都可以通过拖拽其边框改变大小,也可以点击折叠按钮将面板折叠起来。布局可以进行嵌套,用户可以通过组合布局构建复杂的布局结构。



 1. 通过标签创建布局,为<div/>标签增加名为‘easyui-layout‘的类ID。

  1. <div id="cc" class="easyui-layout" style="width:600px;height:400px;">
  2. <div data-options="region:‘north‘,title:‘North Title‘,split:true" style="height:100px;"></div>
  3. <div data-options="region:‘south‘,title:‘South Title‘,split:true" style="height:100px;"></div>
  4. <div data-options="region:‘east‘,iconCls:‘icon-reload‘,title:‘East‘,split:true" style="width:100px;"></div>
  5. <div data-options="region:‘west‘,title:‘West‘,split:true" style="width:100px;"></div>
  6. <div data-options="region:‘center‘,title:‘center title‘" style="padding:5px;background:#eee;"></div>
  7. </div>

2. 使用完整页面创建布局

  1. <body class="easyui-layout">
  2. <div data-options="region:‘north‘,title:‘North Title‘,split:true" style="height:100px;"></div>
  3. <div data-options="region:‘south‘,title:‘South Title‘,split:true" style="height:100px;"></div>
  4. <div data-options="region:‘east‘,iconCls:‘icon-reload‘,title:‘East‘,split:true" style="width:100px;"></div>
  5. <div data-options="region:‘west‘,title:‘West‘,split:true" style="width:100px;"></div>
  6. <div data-options="region:‘center‘,title:‘center title‘" style="padding:5px;background:#eee;"></div>
  7. </body>

3. 创建嵌套布局

  1. <body class="easyui-layout">
  2. <div data-options="region:‘north‘" style="height:100px"></div>
  3. <div data-options="region:‘center‘">
  4. <div class="easyui-layout" data-options="fit:true">
  5. <div data-options="region:‘west‘,collapsed:true" style="width:180px"></div>
  6. <div data-options="region:‘center‘"></div>
  7. </div>
  8. </div>
  9. </body>

4. 通过ajax读取内容

  1. <body class="easyui-layout">
  2. <div data-options="region:‘west‘,href:‘west_content.php‘" style="width:180px" ></div>
  3. <div data-options="region:‘center‘,href:‘center_content.php‘" ></div>
  4. </body>

布局属性

属性名 属性值类型 描述 默认值
fit boolean 如果设置为true,布局组件将自适应父容器。当使用‘body‘标签创建布局的时候,整个页面会自动最大。 false

区域面板属性

区域面板属性定义与panel组件类似,下面的是公共的和新增的属性:

属性名 属性值类型 描述 默认值
title string 布局面板标题文本。 null
region string 定义布局面板位置,可用的值有:north, south, east, west, center。
border boolean 为true时显示布局面板边框。 true
split boolean 为true时用户可以通过分割栏改变面板大小。 false
iconCls string 一个包含图标的CSS类ID,该图标将会显示到面板标题上。 null
href string 用于读取远程站点数据的URL链接 null
collapsible boolean 定义是否显示折叠按钮。(该属性自1.3.3版开始可用) true
minWidth number 最小面板宽度。(该属性自1.3.3版开始可用) 10
minHeight number 最小面板高度。(该属性自1.3.3版开始可用) 10
maxWidth number 最大面板宽度。(该属性自1.3.3版开始可用) 10000
maxHeight number 最大面板高度。(该属性自1.3.3版开始可用) 10000

实例代码下载

时间: 2024-08-28 10:57:52

EasyUI笔记(一)Layout布局的相关文章

ExtJs4 笔记之 layout 布局

本篇讲解Ext另一个重要的概念:布局.一般的容器类控件都是通过配置项items添加子控件的,这些子控件相对于父控件怎么定位呢,这里就要用到布局. 某些容器类控件,它本身默认就集成了一种布局方式,例如比较典型的是:Ext.container.Viewport 布局控件,它其实就是一个border布局的容器,还有Ext.form.Panel.Ext.tab.Panel等.本节我们系统的分析各种布局方式. 一.absolute 这种方式的布局可以对子元素相对于父级容器控件进行绝对定位,它包含了x.y两

easyui实现树形菜单Tab功能、layout布局

一:常见三种前端ui框架 在初学者入门的状态下,我们常见的前端框架有三种且都有自己的官方网站: 1.easyui:官方网站(http://www.jeasyui.net/) 基于jquery的用户页面插件集合,为一些交互的js提供相应的功能,开发者也不需要写特别复杂的javascript方法,可以用html的标签来解决,支持html5可以说算是能满足你的所有需求,节约时间还能扩展需求,虽然简单但是功能强大. 2.Bootstrap:官方网站(http://www.bootcss.com/) Bo

使用easyui进行上左右布局

在后台管理系统开发的过程中,上左右的布局是最常见的页面布局方式,现在我们来看看使用easyui这个jquery前端框架如何快速搭建一个可用的页面框架. 1.在页面中引入easyui所需的文件 1 <%-- 加载easyui的样式文件,bootstrap风格 --%> 2 <link href="${ctx }/css/themes/bootstrap/easyui.css" rel="stylesheet"> 3 <link href=

第二百零二节,jQuery EasyUI,Layout(布局)组件

jQuery EasyUI,Layout(布局)组件 学习要点: 1.加载方式 2.布局属性 3.区域面板属性 4.方法列表 本节课重点了解 EasyUI 中 Layout(布局)组件的使用方法,这个组件依赖于 Panel(面 板)组件和 resizable(调整大小)组件. 一.加载方式 class 加载方式,这个属性一般使用class方法使用 <body id="box" class="easyui-layout"> <div data-opt

EasyUI之layout布局(布局面板的响应事件)

jquery easyui框架中的layout布局: 遇到的问题:1.在五方布局中(north.sourth.east.west.center),east面板中,包含了两个div,其中的下面那个div里包含了tabs选项卡页签,但是页签不随面板的放大缩小而变化.如下图: 当设置east面板中包含的div的data-options:"fit:true"时: 第二个包含tabs的div并没有随着其父容器的大小变化而变化. 问题调试: 1.将第一个div与第二个div调换位置:发现只有处于上

【安卓笔记】抽屉式布局----DrawerLayout

效果如下: DrawerLayout来自support.v4包,所以不用考虑兼容性问题.其次,这种布局类似风靡一时的侧滑菜单,但是比侧滑菜单轻巧许多. 下面介绍这种布局的使用方式. 1.在你的项目中导入support.v4包. 2.编辑一个布局,根节点为android.support.v4.widget.DrawerLayout,此节点下只允许有两个子节点,第一个为将来主页面的内容,第二个节点即为"抽屉"内容,通常是一个ListView.比如: <android.support.

jQuery Easy UI Layout(布局)组件

layout 布局组件,依赖于panel,自己开发个web小程序的时候直接用这个组件布局很方便. 对于一个web程序原来说,特别是像我这种一遇到界面美化问题就找美工的程序员,想自己独立的开发一个东西,除了套用以前的项目中的界面布局之外就没别的 办法了,虽然我们可以用ifame切分出一个界面布局,但是我不会添加样式啊.使用layout组件就可以帮我们快速的有一个界面布局,而且美观效果也看得过去. 看个例子: <!doctype html> <html lang="en"

WPF学习笔记4&mdash;&mdash;Layout之2

下面简单介绍常见的面板. 一.Grid 1.Grid关于调整行列距离有三种方法:绝对大小,自动大小,比例大小.如下: <ColumnDefinition Width="100"></ColumnDefinition> <ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition Width="*"></Co

雷林鹏分享:jQuery EasyUI 窗口 - 窗口与布局

jQuery EasyUI 窗口 - 窗口与布局 Layout 组件可以内嵌在窗口(window)中.我们可以创建一个复杂的布局窗口,甚至不需要写任何的 js 代码.jquery-easyui 框架帮我们在后台做渲染和调整尺寸. 作为一个实例,我们创建一个窗口(window),它包含两个部分,一个放置在左边一个放置在右边.在窗口(window)的左边我们创建一个树形菜单(tree),在窗口(window)的右边我们创建一个 tabs 容器. Library easyui Music Pictur

JS-jQuery-EasyUI-Layout:Layout 布局

ylbtech-tbm-JS-jQuery-EasyUI-Layout:Layout 布局 通过 $.fn.layout.defaults 重写默认的 defaults. 布局(layout)是有五个区域(北区 north.南区 south.东区 east.西区 west 和中区 center)的容器.中间的区域面板是必需的,边缘区域面板是可选的.每个边缘区域面板可通过拖拽边框调整尺寸,也可以通过点击折叠触发器来折叠面板.布局(layout)可以嵌套,因此用户可建立复杂的布局. 1.返回顶部 1