静态MessageBox,代码包含注释,不需要的方法先要注释掉
<html>
<head>
<title>ExtJs-JSON</title>
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css">
<script type="text/javascript" src="ext-all.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<script type="text/javascript" src="locale/ext-lang-zh-CN.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
// Ext.MessageBox.alert(title,text,callback);
Ext.MessageBox.alert('Alert','Show Alert',callBack);
function callBack(id) {
Ext.MessageBox.alert('Result','<font color=red>' + id + '</font>');
}
});
Ext.onReady(function() {
// Ext.MessageBox.prompt(title,text,callback,scope,multilines,defaulttext);
Ext.MessageBox.prompt('Prompt','Input some text: ',callBack,this,true,'DefaultValue');
function callBack(id,msg) {
Ext.MessageBox.alert('Result','<font color=red>' + id + '</font></Br>' + msg);
}
});
Ext.onReady(function() {
// Ext.MessageBox.confirm(title,text,callback);
Ext.MessageBox.confirm('Confirm','Click me!',callBack);
function callBack(id,msg) {
Ext.MessageBox.alert('Result','<font color=red>' + id + '</font></Br>' + msg);
}
});
Ext.onReady(function() {
// Ext.MessageBox.wait(title,text,properties);
Ext.MessageBox.wait('Waiting','Wait!',{text:'Processing!'});
});
Ext.onReady(function(){
// Ext.MessageBox.show(properties);
Ext.MessageBox.show({
title:'Tip',
msg: 'justwe',
modal: true,
prompt: true,
value: "input",
fn: callBack,
buttons: Ext.Msg.YESNOCANCEL,
icon: Ext.Msg.QUESTION,
});
function callBack(id,msg) {
Ext.MessageBox.alert('Result','<font color=red>' + id + ' ' + msg'</font>');
}
});
</script>
</head>
<body>
</body>
</html>
稍微加点动态因素
<html>
<head>
<title>ExtJs-JSON</title>
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css">
<script type="text/javascript" src="ext-all.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<script type="text/javascript" src="locale/ext-lang-zh-CN.js"></script>
<script type="text/javascript">
Ext.onReady(function(){
// update text show time
var msgBox = Ext.MessageBox.show({
title:'Tip',
msg: 'show time',
modal: true,
buttons: Ext.Msg.OK,
fn: function() {
Ext.TaskManager.stop(task);
}
})
var task = {
run:function() {
msgBox.updateText('<font color=red>Time: ' + Ext.util.Format.date(new Date(),'Y-m-d g:i:s A</font>'));
},
interval:1000
}
Ext.TaskManager.start(task);
});
Ext.onReady(function() {
var msgBox = Ext.MessageBox.show({
title:'Tip',
msg: 'show process',
modal: true,
width:300,
progress:true
})
var count = 0;
var percentage = 0;
var progressText = '';
var task = {
run: function() {
count++;
percentage = count/10;
progressText = 'Processing: ' + percentage*100 + '%';
msgBox.updateProgress(percentage,progressText,'<font color=red>Now time: ' + Ext.util.Format.date(new Data(),'Y-m-d g:i:s A</font>'));
if (count > 10) {
Ext.TaskManager.stop(task);
msgBox.hide();
}
},
interval:1000
}
Ext.TaskManager.start(task);
});
</script>
</head>
<body>
</body>
</html>
来个综合的示例
messagebox_all.html
<html>
<head>
<title>消息框综合演示</title>
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css">
<script type="text/javascript" src="ext-all.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<script type="text/javascript" src="locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="messagebox_all.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<h1><font color="red">消息框综合演示</font></h1>
<p>
<b>Alert</b><br/>
只有OK的确认框
<button id="show_alert">演示</button>
</p>
<p>
<b>Confirm</b><br/>
带有YES||NO的选择框
<button id="show_confirm">演示</button>
</p>
<p>
<b>Prompt</b><br/>
带有文本输入的对话框
<button id="show_prompt">演示</button>
</p>
<p>
<b>Show</b><br/>
自定义对话框
<button id="show_show">演示</button>
</p>
<p>
<b>Progress</b><br/>
带有进度条的对话框(手动)
<button id="show_progress">演示</button>
</p>
<p>
<b>Progress_plus</b><br/>
带有进度条的对话框(自动)
<button id="show_progress_plus">演示</button>
</p>
<p>
<b>Icon</b><br/>
带有图标的自定义按钮对话框(手动)
<button id="show_icon">演示</button>
</p>
</body>
</html>
messagebox_all.js
Ext.onReady(function() { Ext.get('show_alert').on('click',function(e) { Ext.MessageBox.alert('演示','<h4><font color=green>点击了alert</font></h4>',null); }); Ext.get('show_confirm').on('click',function(e) { Ext.MessageBox.confirm('演示','<h4><font color=green>点击了confirm</font></h4>',null); }); Ext.get('show_prompt').on('click',function(e) { Ext.MessageBox.prompt('演示','<h4><font color=green>点击了prompt</font></h4>',show_result,this,true,'请在此处输入'); }); Ext.get('show_show').on('click',function(e) { Ext.MessageBox.show({ title: '演示', msg: '<h4><font color=green>点击了show</font></h4>', modal:true, buttons: Ext.Msg.YESNOCANCEL, fn:function(id) { Ext.MessageBox.alert('结果','<h4><font color=red>' + id + '</font></h4>',null); } }); }); Ext.get('show_progress').on('click',function(e) { Ext.MessageBox.show({ title: '演示', msg: '读取中,请等待...', progressText: '加载中...', width:300, progress:true, closable:false, animateTarget: 'show_progress' }); var f = function(v){ return function(){ if(v == 12){ Ext.MessageBox.hide(); show_result('完成', '加载完成!'); }else{ var i = v/11; Ext.MessageBox.updateProgress(i, Math.round(100*i)+'% completed'); } }; }; for(var i = 1; i < 13; i++){ setTimeout(f(i), i*500); } }); Ext.get('show_progress_plus').on('click',function(e) { Ext.MessageBox.show({ title: '演示', msg: '读取中,请等待...', progressText: '加载中...', width:300, wait:true, waitConfig: {interval:200}, iconHeight: 50, animateTarget: 'show_progress_plus' }); setTimeout(function(){ Ext.MessageBox.hide(); show_result('完成', '加载完成!'); }, 8000); }); Ext.get('show_icon').on('click', function(){ Ext.MessageBox.show({ title: '对话框提示图标', msg: '注意左边的图标!', buttons: Ext.MessageBox.OK, buttonText:{ ok:'了解' }, animateTarget: 'show_icon', icon: Ext.Msg.QUESTION, fn:function(id) { Ext.MessageBox.alert('结果','<h4><font color=red>' + id + '</font></h4>',null); } }); }); function show_result(id,msg) { Ext.MessageBox.alert('结果','<h4><font color=red>' + msg + '</font></h4>',null); } });