<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="./ext-4.2.1.883/resources/ext-theme-classic/ext-theme-classic-all.css">
<script type="text/javascript" src="./ext-4.2.1.883/ext-all-debug.js"></script>
<script type="text/javascript" src="./ext-4.2.1.883/locale/ext-lang-zh_CN.js"></script>
</head>
<body>
<p>避免ext重复创建窗体</p>
<button id="btn">显示窗体</button>
</body>
</html>
<script type="text/javascript">
//第一种方式
/*Ext.onReady(function() {
Ext.get('btn').on('click',function(){
Ext.create('Ext.window.Window', {
title:'我的窗体',
height:300,
width:200,
layout:'fit',
modal:true
}).show();
})
})*/
//第二种方式,先实例出窗体
/*Ext.onReady(function(){
var win = Ext.create('Ext.window.Window', {
title:'我的窗体',
height:300,
width:200,
layout:'fit',
closeAction:'hide' //默认为destroy,就是关闭窗口会销毁,定义为hide是关闭窗口只是隐藏
});
Ext.get('btn').on('click',function() {
win.show();
})
})*/
//第三种方式
Ext.onReady(function(){
Ext.get('btn').on('click',function() {
//Ext.getCmp是通过id获取组件
if(!Ext.getCmp('mywin')){
Ext.create('Ext.window.Window', {
id: 'mywin', //定义id
title:'我的窗体',
height:300,
width:200,
layout:'fit',
}).show();
}
})
})
</script>
extjs防止重复创建窗体
最新推荐文章于 2020-06-29 08:02:22 发布