---
title: "EXT工具栏"
author: "kia126"
date: "2013-03-20T10:07:58Z"
tags: ["EXT"]
categories: ["Web前端"]
slug: "ext"
draft: false
lastmod: "2013-03-19T16:58:14Z"
id: 1831972
url: "https://kia126.iteye.com/blog/1831972"
---

面板中可以有工具栏，工具栏可以位于面板顶部或底部，Ext 中工具栏是由Ext.Toolbar 类表示。工具栏上可以存放按钮、文本、分隔符等内容。面板对象中内置了很多实用的工具 栏，可以直接通过面板的tools 配置选项往面板头部加入预定义的工具栏选项。比如下面的 代码： \[code="java"]Ext.onReady(function(){ new Ext.Panel({ renderTo:"hello", title:"hello", width:300, height:200, html:'

# Hello,easyjf open source!

', tools:\[ {id:"save"}, {id:"help",handler:function(){Ext.Msg.alert('help','please help me!');}}, {id:"close"}], tbar:\[{pressed:true,text:'刷新'}] }); });\[/code] 注意我们在Panel的构造函数中设置了tools属性的值，表示在面板头部显示三个工具栏 选项按钮，分别是保存"save"、"help"、"close"三种。 点击help按钮会执行handler中的函数，显示一个弹出对话框，而点击其它的按钮不 会有任何行为产生，因为没有定义他们的heanlder。 除了在面板头部加入这些已经定义好的工具栏选择按钮以外，还可以在顶部或底工具栏 中加入各种工具栏选项。这些工具栏选项主要包括按钮、文本、空白、填充条、分隔符等。 代码： \[code="java"]Ext.onReady(function(){ new Ext.Panel({ renderTo:"hello", title:"hello", width:300, height:200, html:'

# Hello,easyjf open source!

', tbar:\[new Ext.Toolbar.TextItem('工具栏:'), {xtype:"tbfill"}, {pressed:true,text:'添加'}, {xtype:"tbseparator"}, {pressed:true,text:'保存'} ] }); });\[/code] Ext中的工具栏项目主要包含下面的类： Ext.Toolbar.Button－按钮，xtype为tbbutton TextItem－ Ext.Toolbar.Fill－ Separator－ Spacer－ SplitButton－