以下代码来自网上
步骤一:在”Common/js/”下创建js文件SysMsgBox.js
// JScript 文件

var alternateFrame=null;//生成的iframe
var alternateWin=null;

window.alert=showAlert;
window.confirm=showConfirm;

/**
* 人机交互窗口,覆盖自带的
*/
function alternateWindow(){
this.win=null;//生成对话框的窗口对象
this.pBody=null;//生成的body容器对象
this.pBg=null;
this.type=”alert”;//默认的种类是alert
this.FocusWhere=”OK”;//焦点在哪个按钮上
}
/**
* 模仿的alert窗口
*/
function showAlert(info){
alternateWin=new alternateWindow();
var pBody = alternateWin.init();
alternateWin.initAlertBody(pBody,info);
alternateWin.type=”alert”;
}
/**
* 模仿的alert窗口
*/
function showConfirm(info,ok_func,notok_func,ok_str,not_okstr){
alternateWin=new alternateWindow();
var pBody = alternateWin.init();
alternateWin.initConfirmBody(pBody,info,ok_func,notok_func,ok_str,not_okstr);
alternateWin.type=”confirm”;
}
/**
* 作用:初始基本信息
*/
alternateWindow.prototype.init=function() {
if(alternateFrame==null){
alternateFrame=document.createElement(”“)
alternateFrame.style.position=”absolute”;
document.body.appendChild(alternateFrame);
}else{
alternateFrame.style.visibility=”visible”;
}
alternateFrame.style.width=screen.availWidth;
alternateFrame.style.height=screen.availHeight;
alternateFrame.style.left=document.body.scrollLeft;
alternateFrame.style.top=document.body.scrollTop;
alternateFrame.name=alternateFrame.uniqueID;

this.win=window.frames[alternateFrame.name];
this.win.document.write(”

“);
this.win.document.body.style.backgroundColor=”transparent”;
document.body.style.overflow=”hidden”;
this.pBody=this.win.document.body.children[1];
this.pBg=this.win.document.body.children[0];
this.hideAllSelect();
this.initBg();

return this.pBody;
}

/**
* 作用:初始化背景层
*/
alternateWindow.prototype.initBg=function(){
with(this.pBg.style){
position=”absolute”;
left=”0″;
top=”0″;
width=”100%”;
height=”100%”;
visibility=”hidden”;
backgroundColor=”#333333″;
filter=”blendTrans(duration=1) alpha(opacity=30)”;
}
this.pBg.filters.blendTrans.apply();
this.pBg.style.visibility=”visible”;
this.pBg.filters.blendTrans.play();
}
/**
* 作用:初始化显示层
*/
alternateWindow.prototype.initAlertBody=function(obj,info){
with(obj.style){
position=”absolute”;
width=”400″;
height=”150″;
backgroundColor=”#ffffff”;
}
obj.style.left=window.document.body.clientWidth/2-200;
obj.style.top=window.document.body.clientHeight/3;
var str;
str =”

“;
str+=”

“;
str+=”

[提示]
“;
str+=info+”
” +

" onkeydown='parent.alternateWin.onKeyDown(event,this)'"+
" onclick='parent.alternateWin.closeWin()' style='border:solid 1px #666666;background:#cccccc'>” +

“;
obj.innerHTML=str;
this.win.document.body.all.OK.focus();
this.FocusWhere=”OK”;
}

alternateWindow.prototype.onKeyDown=function(event,obj){
switch(event.keyCode){
case 9:
event.keyCode=-1;
if(this.type==”confirm”){
if(this.FocusWhere==”OK”){
this.win.document.body.all.NO.focus();
this.FocusWhere=”NO”;
}else{
this.win.document.body.all.OK.focus();
this.FocusWhere=”OK”;
}
}
break;
case 13:obj.click();;break;
case 27:this.closeWin();break;
}

}
/**
* 作用:初始化显示层 conFirm提示层
*/
alternateWindow.prototype.initConfirmBody=function(obj,info,ok_func,notok_func,ok_str,notok_str){
with(obj.style){
position=”absolute”;
width=”400″;
height=”150″;
backgroundColor=”#ffffff”;
}
if(ok_str==null){
ok_str=”确定”;
}
if(notok_str==null){
notok_str=”取消”
}
obj.style.left=window.document.body.clientWidth/2-200;
obj.style.top=window.document.body.clientHeight/3;
var str;
str=”

“;
str+=”

“;
str+=”

[询问]
“;
str+=info+”
” +

" onkeydown='parent.alternateWin.onKeyDown(event,this)'"+
" onclick='parent.alternateWin.closeWin();parent."+ok_func+"();' " +
" value='"+ok_str+"' style='border:solid 1px #666666;background:#cccccc'>“+
“   
" onkeydown='parent.alternateWin.onKeyDown(event,this)'"+
" onclick='parent.alternateWin.closeWin();" +
" parent."+notok_func+"();' style='border:solid 1px #666666;background:#cccccc'>

“;
obj.innerHTML=str;
this.win.document.body.all.OK.focus();
}

/**
* 作用:关闭一切
*/
alternateWindow.prototype.closeWin=function(){
alternateFrame.style.visibility=”hidden”;
this.showAllSelect();
document.body.style.overflow=”auto”;
}
/**
* 作用:隐藏所有的select
*/
alternateWindow.prototype.hideAllSelect=function(){
var obj;
obj=document.getElementsByTagName(”SELECT”);
var i;
for(i=0;i obj[i].style.visibility="hidden";
}
/**
* 显示所有的select
*/
alternateWindow.prototype.showAllSelect=function(){
var obj;
obj=document.getElementsByTagName("SELECT");
var i;
for(i=0;i obj[i].style.visibility="visible";
}
步骤二:在程序页面上引用该脚本,直接使用alert和confirm函数。




本Blog文章除特别声明之外皆为原创文章,欢迎转载,转载请注明: 转载自JSSAY'S BLOG

本文链接地址: http://www.jssay.com/blog/index.php/2010/05/24/js%e4%b8%ad%e9%87%8d%e5%86%99alert%e5%87%bd%e6%95%b0%e8%bd%ac/


相关文章

标签:

发表评论