1、Alert
/// <reference path="vswd-ext_2.0.2.js" />
Ext.onReady(function(){
Ext.get("btnAlert").on("click",function(){
Ext.MessageBox.alert("请注意","这是ExtJS的提示框");
});
});
<input id="btnAlert" type="button" value="alert框" />
2、Confirm
Ext.onReady(function(){ Ext.get("btn").on("click",function(){ Ext.MessageBox.confirm("请确认","是否真的要删除指定的内容",function(button){ if(button=='yes') Ext.MessageBox.alert("提示","删除成功!"); else return; }); }); });
<input id="btn" type="button" value="对话框" />
3、Prompt
Ext.onReady(function(){ Ext.get("btn").on("click",function(){ Ext.MessageBox.prompt("输入提示框","请输入你的新年愿望:",function(button,text){ if(button=="ok"){ Ext.MessageBox.alert("提示","你的新年愿望是:"+text); } else Ext.MessageBox.alert("提示","你放弃了录入!"); }); }); });
<input id="btn" type="button" value="对话框" />
4、Multi-line Prompt
Ext.onReady(function(){ Ext.get('btn').on('click', function(e){ Ext.MessageBox.show({ title: 'Address', msg: 'Please enter your address:', width:300, buttons: Ext.MessageBox.OKCANCEL, multiline: true, fn: showResultText, animEl: 'btn' }); }); });
<input id="btn" type="button" value="对话框" />
5、Yes/No/Cancel
Ext.onReady(function(){ Ext.get("btn").on("click",function(){ Ext.Msg.show({ title:'保存数据', msg: '你已经作了一些数据操作,是否要保存当前内容的修改?', buttons: Ext.Msg.YESNOCANCEL, fn: save, icon: Ext.MessageBox.QUESTION}); }); }); function save(button) { if(button=="yes") { //执行数据保存操作 } else if(button=="no") { //不保存数据 } else { //取消当前操作 } }
Ext.onReady(function(){ Ext.get("btn").on("click",function(){ ShowMessageBox('保存数据','你已经作了一些数据操作,是否要保存当前内容的修改?', Ext.Msg.YESNOCANCEL,save,Ext.MessageBox.QUESTION); }); }); function save(button) { if(button=="yes") { //执行数据保存操作 } else if(button=="no") { //不保存数据 } else { //取消当前操作 } } function ShowMessageBox(title, message, button, callBack, icon) { Ext.MessageBox.buttonText.ok = '确定'; Ext.MessageBox.buttonText.yes = '是'; Ext.MessageBox.buttonText.no = '否'; Ext.MessageBox.buttonText.cancel = '取消'; Ext.MessageBox.show({ title: title, msg: message, buttons: button, fn: callBack, icon: icon }); };
Ext.onReady(function(){ Ext.get('btn').on('click', function(){ Ext.MessageBox.show({ title: 'Please wait', msg: 'Loading items...', progressText: 'Initializing...', width:300, progress:true, closable:false, animEl: 'btn' }); // this hideous block creates the bogus progress var f = function(v){ return function(){ if(v == 12){ Ext.MessageBox.hide(); Ext.example.msg('Done', 'Your fake items were loaded!'); }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); } }); });
<input id="btn" type="button" value="对话框" />
7、Wait Dialog
Ext.onReady(function(){ Ext.get('btn').on('click', function(){ Ext.MessageBox.show({ msg: 'Saving your data, please wait...', progressText: 'Saving...', width:300, wait:true, waitConfig: {interval:200}, icon:'ext-mb-download', //custom class in msg-box.html animEl: 'btn' }); setTimeout(function(){ //This simulates a long-running operation like a database save or XHR call. //In real code, this would be in a callback function. Ext.MessageBox.hide(); Ext.example.msg('Done', 'Your fake data was saved!'); }, 8000); }); });
<input id="btn" type="button" value="对话框" />
8、Icons
Ext.onReady(function(){ //Add these values dynamically so they aren't hard-coded in the html Ext.fly('info').dom.value = Ext.MessageBox.INFO; Ext.fly('question').dom.value = Ext.MessageBox.QUESTION; Ext.fly('warning').dom.value = Ext.MessageBox.WARNING; Ext.fly('error').dom.value = Ext.MessageBox.ERROR; Ext.get('mb9').on('click', function(){ Ext.MessageBox.show({ title: 'Icon Support', msg: 'Here is a message with an icon!', buttons: Ext.MessageBox.OK, animEl: 'mb9', fn: showResult, icon: Ext.get('icons').dom.value }); }); });
<p> <b>Icons</b><br /> Standard alert with optional icon. <select id="icons"> <option id="error" selected="selected">Error</option> <option id="info">Informational</option> <option id="question">Question</option> <option id="warning">Warning</option> </select> <button id="mb9">对话框</button> </p>