模拟实现msgbox
今天去无忧论坛看到biyuan版主写了一个模拟实现msgbox代码,就收藏了,在实现应用web开发中,可能会用到的!
document.writeln("");
//向模拟提示框传递参数,并激活对话框
function msg(str1,str2,str3,str4,str5){
   document.getElementById("div_01").style.width = str3;
   document.getElementById("div_01").style.left = (document.body.clientWidth-str3)/2;
   document.getElementById("div_01").style.top = (document.body.clientHeight-120)/2;
   document.getElementById("div_01").style.display = '';
   document.getElementById("msgbox").innerHTML = str1;
   if(str2 == 1){
      document.getElementById("con_01").innerHTML = "确定";
   }
   if(str2 == 2){
      document.getElementById("con_01").innerHTML = "确定 取消";
   }
   document.getElementById("mdiv").style.display = "";
   document.getElementById("mdiv").style.zIndex = 100;
   document.getElementById("div_01").style.zIndex = 200;
   document.getElementById("but_01").focus();
}
//加入对话框移动代码
   var md=false,mobj,ox,oy
   function document.onmousedown(){
      if(typeof(event.srcElement.canmove)=="undefined")return;
      if(event.srcElement.canmove)
      {
         md = true;
         mobj = document.getElementById(event.srcElement.forid);
         ox = mobj.offsetLeft - event.x;
         oy = mobj.offsetTop - event.y;
      }
   }
   function document.onmouseup(){md=false;}
   function document.onmousemove()
   {
      if(md)
      {
         mobj.style.left = event.x + ox;
         mobj.style.top = event.y + oy;
      }
      if(document.activeElement.tagName!='INPUT')return false;
   }
document.writeln("");
document.writeln("");
document.writeln("");
document.writeln("   ");
document.writeln("      ");
document.writeln("      VBScript提示");
document.writeln("      ");
document.writeln("      ");
document.writeln("   ");
document.writeln("");
document.writeln("");
document.writeln("   ");
document.writeln("      ");
document.writeln("      ");
document.writeln("      ");
document.writeln("   ");
document.writeln("   ");
document.writeln("      ");
document.writeln("      ");
document.writeln("      ");
document.writeln("   ");
document.writeln("");
document.writeln("")
 [/code]
调用方式:
<Script Language="JavaScript" src="MsgBox.js"></script>
测试
函数结构:
msg("count","type","width","turn","false")
参数说明:
msg                主函数
count                提示框显示的正文
type                提示框类型,1为只有确定按纽,2为确定按纽和取消按纽
width                提示框宽度,取值范围应大于140
turn                点击确定后执行的语句或函数
false                点击取消后执行的语句或函数
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号