ExtJS—window组件Listeners的使用

本文介绍如何在ExtJS中为窗口添加关闭监听事件,并通过示例代码展示了如何使用hide方法而非close方法来避免重复创建窗口时出现错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用场景:关闭window的时候增加监听事件。

正确的使用方式:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 1 Ext.onReady(function(){
 2     var win;
 3     var button = Ext.get('show-btn');
 4 
 5     button.on('click'function(){
 6         // create the window on the first click and reuse on subsequent clicks
 7         if(!win){
 8             win = new Ext.Window({
 9                 applyTo     : 'hello-win',
10                 layout      : 'fit',
11                 width       : 500,
12                 height      : 300,
13                 closeAction :'hide',
14                 plain       : true,
15                 listeners   : {'hide':{fn: makesure}},
16                 modal:true,
17                 items       : new Ext.TabPanel({
18                     applyTo        : 'hello-tabs',
19                     autoTabs       : true,
20                     activeTab      : 0,
21                     deferredRender : false,
22                     border         : false
23                 }),
24 
25                 buttons: [{
26                     text     : 'Submit',
27                     disabled : true
28                 },{
29                     text     : 'Close',
30                     handler  : function(){
31                         win.hide();
32                     }
33                 }]
34             });
35         }        
36         win.show(button);
37     });
38     function makesure(){
39         alert('close success');
40     }
41     
42 });

 

html代码:

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 1<html>
 2<head>
 3<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 4    <title>Hello World Window Example</title>
 5    <link rel="stylesheet" type="text/css" href="http://www.cnblogs.com/resources/css/ext-all.css" />
 6
 7    <!-- GC -->
 8     <!-- LIBS -->
 9     <script type="text/javascript" src="http://www.cnblogs.com/adapter/ext/ext-base.js"></script>
10     <!-- ENDLIBS -->
11
12    <script type="text/javascript" src="http://www.cnblogs.com/ext-all.js"></script>
13
14    <script language="javascript" src="lj-hello.js"></script>
15
16<!-- Common Styles for the examples -->
17<link rel="stylesheet" type="text/css" href="../shared/examples.css" />
18
19ExpandedBlockStart.gifContractedBlock.gif    <style type="text/css">
20ExpandedSubBlockStart.gifContractedSubBlock.gif    .x-panel-body p {}{
21        margin:10px;
22        font-size:12px;
23    }

24    
</style>
25</head>
26<body>
27<script type="text/javascript" src="../shared/examples.js"></script><!-- EXAMPLES -->
28
29<h1>Hello World Window</h1>
30<p>This example shows how to create a very simple modal Window with "autoTabs" from existing markup.</p>
31<input type="button" id="show-btn" value="Hello World" /><br /><br />
32<p>Note that the js is not minified so it is readable. See <href="hello.js">hellos.js</a> for the full source code.</p>
33
34<div id="hello-win" class="x-hidden">
35    <div class="x-window-header">Hello Dialog</div>
36    <div id="hello-tabs">
37        <!-- Auto create tab 1 -->
38        <div class="x-tab" title="Hello World 1">
39            <p>Hello</p>
40        </div>
41        <!-- Auto create tab 2 -->
42        <div class="x-tab" title="Hello World 2">
43            <p> World!</p>
44        </div>
45    </div>
46</div>
47</body>
48</html>
49

注意:关闭窗口使用hide方法。过使用close方法,在第二次通过button创建window的时候会报错。

作者: 向阳 发表于 2009-06-20 01:00 原文链接

评论: 0 查看评论 发表评论


最新新闻:
· API对设计流程的影响——Joshua Bloch访谈(2010-12-15 20:54)
· 50个有关编程的至理名言(2010-12-15 20:50)
· 亚马逊再次远程删除用户kindle电子书(2010-12-15 20:49)
· 东芝否认苹果投资其液晶面板新厂传闻(2010-12-15 20:47)
· 百度高级副总裁沈皓瑜:明年营收增速将放缓(2010-12-15 20:39)

编辑推荐:“博客无双“活动:写博客、攒园豆、赢大奖

网站导航:博客园首页  我的园子  新闻  闪存  小组  博问  知识库

转载于:https://www.cnblogs.com/mingle/articles/1907251.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值