Ext.MessageBox

1.Ext.MessageBox.alert()方法
      有四個參數,爲簡單起見,主要介紹前面三個參數:
      alert( title , msg , function(){} )
      其中title,msg爲必選參數,function爲可選參數,在關閉彈出窗口後觸發。

Ext.MessageBox.alert("title","msg");

 

Ext.MessageBox.alert("title","msg",function(){alert("關閉對話框後彈出!")});

2.Ext.MessageBox.confirm()方法
   基本上同alert()方法一模一樣。
   注意這點:

Ext.MessageBox.confirm("title","msg",function(e){alert(e);});

這個參數e是什麼?它是你點擊的彈出框的按鈕的值,三種值:yes,no,cancel.Alert()方法也是如此,不過只有兩種值:ok,cancel.

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

Ext.MessageBox.prompt("title","msg");

 

Ext.MessageBox.prompt("title","msg",function(e,text){alert(e+"-"+text);});
//輸入"qianxudetianxia",點擊ok按鈕,彈出ok-qianxudetianxia

 

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.CAMCEL,
                                         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

example:

Ext.MessageBox.show({
     title:
"標題",
     msg:
"內容的消息",
     buttons:{
"ok":"我不再顯示OK了"},
     fn:
function(e){alert(e);},
     animEl:
"test1",
      width:
500,
     icon:Ext.MessageBox.INFO,
     closable:
false,
     progress:
true,
     wait:
true,
     progressText:
"進度條"
   
// prompt:true
   // multiline:true
});

4.Ext.MessageBox.show()中的進度條的使用
    首先必須知道例外兩個方法 Ext.MessageBox.hide()和Ext.MessageBox.updateProgress(value,"ProgressText","msg")(三個參數,看名字就知道意思),
   注意value爲0-1之間的數,表示進度條的進度.
   第一種:(通過進度的大小控制進度,滿進度爲1)

Ext.get("btn1").on(
          
"click",
          
function(){
              Ext.MessageBox.show({
                  title:
"df",
                  msg:
"dfd",
                  progress:
true,
                  width:
300,
                  closable:
true
              });
             
var f=function(v){
               
return function(){
                 
if(v==12)
                  {
                    Ext.MessageBox.hide();
                   
//alert("加載完成!");
                  }
                 
else
                  {
                   
var i=v/11;
                    Ext.MessageBox.updateProgress(i,Math.round(100*i)+"% completed",i);
                  }
                }
              }
             
for(var i=1;i<13;i++)
              {
                setTimeout(f(i),i
*500);//從點擊時就開始計時,所以500*i表示每500ms就執行一次
              }
           }
    );


   第二種:(通過固定時間控制進度加載)

Ext.get("btn1").on(
          
"click",
          
function(){
              Ext.MessageBox.show({
                  title:
"時間進度條",
                  msg:
"5s後關閉進度框",
                  progress:
true,
                  width:
300,
                  wait:
true,
                  waitConfig:{interval:
600},//0.6s進度條自動加載一定長度
                  closable:true
              });
              setTimeout(
function(){Ext.MessageBox.hide()},5000);//5後執行關閉窗口函數
           }


最後關於那個waitConfig的參數,在此說明下:

1.interval:進度的頻率
2.duration:執行進度的持續時間,超過這個時間後,interval失效,不再產生進度效果,但進度狂也不會消失。
3.fn:duration的時間到後執行的函數
所以,上面的通過時間控制進度另外一種寫法爲:
     Ext.get(
"btn1").on(
          
"click",
          
function(){
              Ext.MessageBox.show({
                  title:
"時間進度條",
                  msg:
"5s後關閉進度框",
                  progress:
true,
                  width:
300,
                  wait:
true,
                  waitConfig:{
                               interval:
600,
                               duration:
5000,
                               fn:
function(){
                                 Ext.MessageBox.hide();
//讓進度條消失
                               }},
                  closable:
true
              });
             
//setTimeout(function(){Ext.MessageBox.hide()},5000);
           }
    );
效果一樣
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章