ext MessageBox 用法

來源:互聯網
上載者:User

1.Ext.MessageBox.alert()方法 
有四個參數:alert( title , msg , function(){} ,this) 
其中title,msg為必選參數,function為選擇性參數,在關閉快顯視窗後觸發,可以傳入點擊的按鈕的id,第四個參數scope:指回呼函數範圍。 

Ext.Msg.alert("Notice","hello world!");  //alert會阻塞程式的執行,而Ext版的alert是非同步執行 
Ext.Msg.alert(“Notice”,”<font color=red>hello world!</font>”); //支援html格式 
Ext.Msg.alert(“Notice”,”<font color=red>hello world!</font>”,function callback(id){alert(‘您點的是’+id);}); 

2.Ext.MessageBox.confirm()方法 

基本上同alert()方法一模一樣。 注意這點: 

Ext.MessageBox.confirm(“title“,“msg“,function(e){alert(e);}); 
這個參數e是什嗎?它是你點擊的彈出框的按鈕的值,三種值:yes,no,cancel. Alert()方法也是如此,不過只有兩種值:ok,cancel. 

回呼函數可以傳入一唯一參數:單擊按鈕的id,點擊退出按鈕也會觸發此事件 

3.Ext.MessageBox.prompt()方法 
有五個參數,比前面alert方法多一個是否多行。 

Ext.MessageBox.prompt(“title“,"msg"); 
Ext.Msg.prompt(‘Notice’,'請輸入你的姓名:’,function callback(id,msg){alert(‘單擊的按鈕ID:’+id+’\n您輸入的姓名是:’+msg);},this,false); 
//輸入”javachen”,點擊ok按鈕,彈出單擊的按鈕ID:OK 您輸入的姓名是:javachen 
Ext.MessageBox.prompt(“title“,“msg“,function(e,text){alert(e+“-“+text);},this,true);//true為多行,this表示範圍 
4.Ext.MessageBox.show()方法 
功能很強大,採用config配置形式,比前面的方法使用更方便。 參數很多,在此列舉最常用的配置參數: 

1.animEl:對話方塊彈出和關閉時的動畫效果,比如設定為“id1”,則從id1處彈出併產生動畫,收縮則相反 
2.buttons:彈出框按鈕的設定,主要有以下幾種:Ext.Msg.OK, 
Ext.Msg.OKCANCEL, 
Ext.Msg.CANCEL, 
Ext.Msg.YESNO, 
Ext.Msg.YESNOCANCEL 
你也可以自訂按鈕上面的字:{“ok“,“我本來是ok的“}。 若設為false,則不顯示任何按鈕. 
3.closable:如果為false,則不顯示右上方的小叉叉,預設為true。 
4.msg:“訊息的內容“ 
5.title:“標題“ 
6.fn:關閉彈出框後執行的函數 
7.icon:彈出框內容前面的表徵圖,取值為Ext.MessageBox.INFO, 
Ext.MessageBox.ERROR, 
Ext.MessageBox.WARNING, 
Ext.MessageBox.QUESTION 
8.width:彈出框的寬度,不帶單位 
9.prompt:設為true,則彈出框帶有輸入框 
10.multiline:設為true,則彈出框帶有多行輸入框 
11.progress:設為true,顯示進度條,(但是是死的) 
12.progressText:顯示在進度條上的字 
13.wait:設為true,動態顯示progress 
14.waitConfig:配置參數,以控制顯示progress 
例子: 
Ext.Msg.show({ 
title:’Notice’, 
msg:’請輸入您的姓名!’, 
width:300, 
prompt:true, 
//multiline:true, 
//wait:true, 
//progress:true, 
//progressText:’progressing’, 
closable:true, 
modal:true, 

buttons:Ext.Msg.OKCANCEL, 
icon:Ext.Msg.INFO 
}); 

5.Ext.MessageBox.wait() 
參數 msg:顯示資訊  title:標題      config:配置資訊 
例子: 
Ext.Msg.wait(‘請等待,操作進行中中’,'Notice’); 
Ext.Msg.wait(‘請等待,操作進行中中!’,'Notice’, 

text:’processing’, 
duration:2700,   //進度條在被重設前啟動並執行時間 
interval:300,        //進度條的時間間隔 
increment:10,      //進度條的分段數量 
fn:function callback(){ 
alert(“complete”); 

}); 
6.Ext.MessageBox.hide() 
把顯示著的當前message box隱藏起來。 
參數: 無.       Returns:   Ext.MessageBox 
7.Ext.MessageBox.updateProgress() 
Ext.MessageBox.updateProgress(value,”ProgressText”,”msg”)  //(三個參數,看名字就知道意思), 注意value為0-1之間的數,表示進度條的進度. 

8.修改預設的按鈕文字為中文 
Ext.Msg.buttonText={ 
yes:' yes', 
no:'否', 
ok:'確定', 
cancel:'取消' 
}; 
Ext.Msg.buttonText.yes='是'; 
9.動態跟新提示框 
1)跟新提示文字 
var msgBox = Ext.MessageBox.show({ 
title:’提示’, 
msg:’動態跟新的資訊文字’, 
modal:true, 
buttons:Ext.Msg.OK 
}) 
//Ext.TaskMgr是一個功能類,用來定時執行程式, 
//在這裡我們使用它來定時觸發提示資訊的更新。 
Ext.TaskMgr.start({ 
run:function(){ 
msgBox.updateText(‘會動的時間:’+new Date().format(‘Y-m-d g:i:s A’)); 
}, 
interval:1000 
}); 
2).跟新進度條及提示資訊 
var msgBox = Ext.MessageBox.show({ 
title:’提示’, 
msg:’動態跟新的進度條和資訊文字’, 
modal:true, 
width:300, 
progress:true 
}) 

var count = 0;//捲軸被重新整理的次數 
var percentage = 0;//進度百分比 
var progressText = ”;//進度條資訊 

Ext.TaskMgr.start({ 
run:function(){ 
count++;   //重新整理10次後關閉資訊提示對話方塊 
if(count > 10){ 
msgBox.hide(); 

//計算進度 
percentage = count/10; 
//產生進度條文字 
progressText = ‘當前完成度:’+percentage*100 + “%”; 
//更新資訊提示對話方塊 
msgBox.updateProgress(percentage,progressText, 
‘目前時間:’+new Date().format(‘Y-m-d g:i:s A’)); 

}, 
interval:1000 
}); 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.