模擬彈出訊息框

2021-08-30 18:59:28 字數 2104 閱讀 6699

模擬乙個彈出訊息框,有模式。核心介面是open,即彈出訊息框,此方法有三個引數,分別代表訊息框的標題,需要顯示的內容,客戶端提供的其他引數(引數間用分號隔開)。

以下是**,附件是demo。

/*** 用層來模擬的訊息框,有模式

*/function divalert()

}//執行自定義的確定動作,由客戶端提供

if(typeof(window.confirmfct)!="undefined")

_binmodel=false;

}//開啟提示框

this.open=function open($title,$content,$params)catch(e)

_bshow=true;

};//關閉提示框

this.close=function close()

}_binmodel=false;

};//設定提示框的標題

this.settitle=function settitle($title)

//設定提示框需要顯示的內容

this.setcontent=function setcontent($content)

_domcontent.innertext=$content;

}//判斷提示框是否開啟

this.isopen=function()

this.getnode=function()

//為body設定模式

this.setmodel=function setmodel()

document.body.insertadjacenthtml("beforeend",_model);

if(_modeldom==null)

fixmodellayer();

_modeldom.style.display="";

_binmodel=true;

}this.getmodeldom=function()

}//修正層的大小

this.fixmodellayer=function fixmodellayer()

if(document.body.scrollleft>0)else

if(document.body.scrolltop>0)else

}//層移動時同時改變模式的大小

this.changemodelpos=function changemodelpos()

var st=document.body.scrolltop;

var sw=document.body.scrollleft;

if(st!=0)else

if(sw!=0)else

}}var _divalert = new divalert();

//拖動提示框的同時調整模式層的大小

function withdrag()

//產生乙個外圍面板

function panel();

// show or hide the layer

this.setvis = function($btype) ;

}function createspanhtml($html)

//解析由分號分隔的引數,格式如nowrap=true;height=100;width=100

function parseparams($params){

var reg = /([^\=\;]*)\=([^\;]*)/gi;

var rt = ;

if ($params==null)

return rt;

var ar = $params.match(reg);

var t = null;

for (var i=0; i程式中拖動層的方法還沒提供。用ie除錯通過,沒試過其他瀏覽器。

必須注意的一點是,在demo中,呼叫介面open的**必須在之後,否則會有document.body不是物件的bug,不知道是不是ie的問題,我除錯用ie7。

另外,建立模式的層的大小必須隨著提示框的位置而變化(如果提示框被拉出當前視窗之外,即出現垂直或者水平滾動條),這裡解決這個問題的思路是,在拖動層的onmouseup的事件函式中同時呼叫乙個函式(以上提供了原型withdrag),這個函式會同時改變模式層的大小。

android 彈出訊息框

那麼這種效果是如何實現的呢,其實很簡單,這用到了系統中的兩個類 notification和notificationmanager 乙個簡單例子 比如說鬧鐘1 布局檔案 xmlns android android orientation vertical android layout width fi...

js彈出提問框訊息框警告框

警告 alert 在訪問 的時候,你遇到過這樣的情況嗎?咚 的一聲,乙個小視窗出現在你面前,上面寫著一段警示性的文字,或是其它的提示資訊。如果你不點選確定,你就不能對網頁做任何的操作。沒錯,這個 咚 的小視窗就是alert幹的。下面的 是一段使用alert的例項。我的個人觀點是盡量少使用alert,...

MessageBox頁面訊息彈出框類

messagebox頁面訊息彈出框類 public class messagebox 自定義彈出視窗內容,並跳轉 public static void show system.web.ui.page page,string msg,string returnurl 自定義彈出視窗內容,並跳轉 pub...