[JavaScript]自定义MessageBox

简介:

前言:

    继上文([JavaScript]自定义Title的显示方式)之后,我的工作是进一步增强一些IE所不能提供的东东.

    还记得Windows下的MessageBox嘛?

    IE呢?Alert?Confirm? 是不是好丑呢?

    不过丑就算了,关键是还不好用.

    本次的目标是,提供好看又好用的Web版的Windows MessageBox.(已测试,兼容IE和FF)

正文:

    首先自然是先画好Html下的对话框样子了(用层来模拟):


    画得不专业,先用着,反正后面可以通过css来调整.

    接下来的工作就是需要通过Javascript动态输入这个层的内容.首先参考[JavaScript]自定义Title的显示方式中的方式,代码虽然很多,不过只不过比[JavaScript]自定义Title的显示方式多了几个层而已,大同小异:
   

  1 None.gif
  2 ExpandedBlockStart.gif ContractedBlock.gifKMessageBox =  dot.gif {
  3InBlock.gif  name: "KMessageBox",
  4InBlock.gif  capiton : "消息框",
  5InBlock.gif  content: "提示消息",
  6InBlock.gif  msgbox : null,
  7InBlock.gif  msgcaptioninfo:null,
  8InBlock.gif  msgcontent:null,
  9InBlock.gif  msgContenttxtmsg:null,
 10InBlock.gif  msgbuttonyes:null,
 11InBlock.gif  msbbuttonno:null,
 12InBlock.gif  msgico:null 
 13ExpandedBlockEnd.gif}
;
 14 None.gif
 15 ExpandedBlockStart.gif ContractedBlock.gifKMessageBox.init =  function ()  dot.gif {
 16InBlock.gif    var msgNameSpaceURI = "http://www.w3.org/1999/xhtml";
 17InBlock.gif    
 18ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContainerID)dot.gifvar msgContainerID= "KMessageBox"; }
 19InBlock.gif
 20ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgCaptionID)dot.gifvar msgCaptionID= "KMessageBox_caption"; }
 21ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgCaptionInfoID)dot.gif{var msgCaptionInfoID = "KMessageBox_caption_info";}
 22ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContentID)dot.gifvar msgContentID = "KMessageBox_content"; }
 23ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContentTxtID)dot.gifvar msgContentTxtID= "KMessageBox_content_txt"; }
 24ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContentTxtICOID)dot.gif{var msgContentTxtICOID="KMessageBox_content_txt_ico"};
 25ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContentTxtMsgID)dot.gif{var msgContentTxtMsgID="KMessageBox_content_txt_msg"};
 26ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgButtons)dot.gif{var msgButtonsID="KMessageBox_buttons"};
 27ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgButtonYes)dot.gif{var msgButtonYesID="KMessageBox_buttons_yes"};
 28ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgButtonNo)dot.gif{var msgButtonNoID="KMessageBox_buttons_no"};    
 29ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgButtonOK)dot.gif{var msgButtonOKID="KMessageBox_buttons_ok"};    
 30InBlock.gif
 31InBlock.gif    var msgContainer = $(msgContainerID);
 32ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContainer) dot.gif{
 33InBlock.gif      msgContainer = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div");
 34InBlock.gif      msgContainer.setAttribute("id", msgContainerID);
 35InBlock.gif      msgContainer.setAttribute("style","MARGIN: 0px auto; POSITION: absolute; TEXT-ALIGN: center;");
 36InBlock.gif
 37InBlock.gif
 38InBlock.gif    var msgCaption = $(msgCaptionID);
 39InBlock.gif
 40ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgCaption)dot.gif{
 41InBlock.gif      msgCaption = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 42InBlock.gif      msgCaption.setAttribute("id",msgCaptionID);
 43InBlock.gif      Element.addClassName(msgCaption,"caption");      
 44InBlock.gif
 45InBlock.gif      
 46InBlock.gif      var msgCaptionInfo = $(msgCaptionInfoID);
 47ExpandedSubBlockStart.gifContractedSubBlock.gif      if(!msgCaptionInfo)dot.gif{
 48InBlock.gif      msgCaptionInfo = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 49InBlock.gif      msgCaptionInfo.setAttribute("id",msgCaptionInfoID);
 50InBlock.gif      Element.addClassName(msgCaptionInfo,"info");
 51InBlock.gif      msgCaption.appendChild(msgCaptionInfo);
 52ExpandedSubBlockEnd.gif      }

 53InBlock.gif      msgContainer.appendChild(msgCaption);
 54InBlock.gif      
 55ExpandedSubBlockEnd.gif    }

 56InBlock.gif    
 57InBlock.gif    var msgContent = $(msgContentID);
 58InBlock.gif
 59ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContent)dot.gif{
 60InBlock.gif      msgContent= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 61InBlock.gif      msgContent.setAttribute("id",msgContentID);
 62InBlock.gif      Element.addClassName(msgContent,"content");
 63InBlock.gif      
 64InBlock.gif      var msgContentTxt = $(msgContentTxtID);
 65InBlock.gif      
 66ExpandedSubBlockStart.gifContractedSubBlock.gif      if(!msgContentTxt )dot.gif{
 67InBlock.gif      msgContentTxt = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 68InBlock.gif      msgContentTxt.setAttribute("id",msgContentTxtID);
 69InBlock.gif      Element.addClassName(msgContentTxt,"txt");
 70InBlock.gif           
 71InBlock.gif      var msgContentTxtICO = $(msgContentTxtICOID);
 72InBlock.gif      if(!msgContentTxtICO)
 73ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{
 74InBlock.gif         msgContentTxtICO= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "img") : document.createElement("img") ;
 75InBlock.gif         msgContentTxtICO.setAttribute("id",msgContentTxtICOID);
 76InBlock.gif         msgContentTxtICO.setAttribute("src","icon_alarm.gif");
 77InBlock.gif         msgContentTxtICO.setAttribute("align","absMiddle");
 78InBlock.gif         msgContentTxtICO.setAttribute("style","height:52px;width:64px;background-image:url('icon_big_info.gif');");
 79InBlock.gif         msgContentTxt.appendChild(msgContentTxtICO);
 80ExpandedSubBlockEnd.gif      }

 81InBlock.gif      
 82InBlock.gif      var msgContentTxtMsg= $(msgContentTxtMsgID);
 83InBlock.gif      if(!msgContentTxtMsg)
 84ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{
 85InBlock.gif         msgContentTxtMsg= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "span") : document.createElement("span") ;
 86InBlock.gif         msgContentTxtMsg.setAttribute("id",msgContentTxtMsgID);
 87InBlock.gif         
 88InBlock.gif         msgContentTxt.appendChild(msgContentTxtMsg);
 89ExpandedSubBlockEnd.gif      }

 90InBlock.gif
 91InBlock.gif
 92InBlock.gif      var msgButtons = $(msgButtonsID);
 93InBlock.gif      if(!msgButtons)
 94ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{
 95InBlock.gif         msgButtons = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 96InBlock.gif         msgButtons.setAttribute("id",msgButtonsID);
 97InBlock.gif         Element.addClassName(msgButtons,"btnlist");
 98InBlock.gif         var msgButtonYes = $(msgButtonYesID);
 99InBlock.gif          if(!msgButtonYes)
100ExpandedSubBlockStart.gifContractedSubBlock.gif          dot.gif{
101InBlock.gif            msgButtonYes= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
102InBlock.gif            msgButtonYes.setAttribute("id",msgButtonYesID);
103InBlock.gif            msgButtonYes.setAttribute("type","button");
104InBlock.gif            msgButtonYes.setAttribute("value","YES");
105InBlock.gif            Element.addClassName(msgButtonYes,"input_set");
106InBlock.gif                    
107InBlock.gif            msgButtons.appendChild(msgButtonYes);             
108ExpandedSubBlockEnd.gif         }

109InBlock.gif
110InBlock.gif         var msgButtonNo = $(msgButtonNoID);
111InBlock.gif          if(!msgButtonNo)
112ExpandedSubBlockStart.gifContractedSubBlock.gif          dot.gif{
113InBlock.gif            msgButtonNo= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
114InBlock.gif            msgButtonNo.setAttribute("id",msgButtonNoID);
115InBlock.gif            msgButtonNo.setAttribute("type","button");
116InBlock.gif            msgButtonNo.setAttribute("value","NO");
117InBlock.gif            Element.addClassName(msgButtonNo,"input_set");
118InBlock.gif            
119InBlock.gif            msgButtons.appendChild(msgButtonNo); 
120InBlock.gif            
121ExpandedSubBlockEnd.gif         }

122InBlock.gif         
123InBlock.gif         var msgButtonOK= $(msgButtonOKID);
124InBlock.gif          if(!msgButtonOK)
125ExpandedSubBlockStart.gifContractedSubBlock.gif          dot.gif{
126InBlock.gif            msgButtonOK= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
127InBlock.gif            msgButtonOK.setAttribute("id",msgButtonOKID);
128InBlock.gif            msgButtonOK.setAttribute("type","button");
129InBlock.gif            msgButtonOK.setAttribute("value","OK");
130InBlock.gif            Element.addClassName(msgButtonOK,"input_set");
131InBlock.gif            
132InBlock.gif            msgButtons.appendChild(msgButtonOK); 
133InBlock.gif            
134ExpandedSubBlockEnd.gif         }

135InBlock.gif
136InBlock.gif
137InBlock.gif         msgContentTxt.appendChild(msgButtons);
138ExpandedSubBlockEnd.gif      }

139InBlock.gif      
140InBlock.gif      msgContent.appendChild(msgContentTxt);
141ExpandedSubBlockEnd.gif      }

142InBlock.gif
143InBlock.gif      
144InBlock.gif      msgContainer.appendChild(msgContent);
145ExpandedSubBlockEnd.gif    }

146InBlock.gif
147InBlock.gif     document.getElementsByTagName("body").item(0).appendChild(msgContainer);
148ExpandedSubBlockEnd.gif    }

149InBlock.gif       
150InBlock.gif    this.msgbox = $(this.name);
151InBlock.gif    this.msgcaptioninfo = $(msgCaptionInfoID);
152InBlock.gif    this.msgContenttxtmsg= $(msgContentTxtMsgID);
153InBlock.gif    this.msgbuttonyes = $(msgButtonYesID);
154InBlock.gif    this.msgbuttonno = $(msgButtonNoID);
155InBlock.gif    this.msgbuttonok = $(msgButtonOKID);
156InBlock.gif    this.msgico = $(msgContentTxtICOID);
157InBlock.gif    Element.hide(this.msgbox);
158InBlock.gif   
159ExpandedBlockEnd.gif}

160 None.gif
161 None.gif

    接下来应该为MessageBox提供行为能力.我们需要模拟Confirm和Alert.
    原始的Confrim需要返回false或者true来决定是否要运行postback事件.
    在这里我转换了一下思路,不返回值,而是直接将postback事件的脚本(_doPostBack('',''))传入MessageBox,并绑定到相关的按钮上.所以我们的需要接受传入的参数主要有:消息标题,消息内容,按钮事件
    OK,接下来构造Javascript中MessageBox的ShowConfirm函数:

 1 ExpandedBlockStart.gif ContractedBlock.gifKMessageBox.ShowConfirm =  function (imgdir,caption,msg,YesClick,NoClick)  dot.gif {
 2InBlock.gif    
 3InBlock.gif    if (!this.msgbox ) return;
 4InBlock.gif    
 5InBlock.gif    this.msgcaptioninfo.innerHTML = caption;
 6InBlock.gif    this.msgContenttxtmsg.innerHTML = msg;
 7InBlock.gif    //为了提示消息前面的图片可以适应实际的相对位置,传入程序父目录,主要为封装为Server控件做准备
 8InBlock.gif       if(imgdir != "")
 9ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
10InBlock.gif         this.msgico.setAttribute("src",imgdir+"/kinnsoft_client/KMessageBox/icon_alarm.gif");
11ExpandedSubBlockEnd.gif       }

12InBlock.gif       else
13ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif{
14InBlock.gif         this.msgico.setAttribute("src","/kinnsoft_client/KMessageBox/icon_alarm.gif");
15ExpandedSubBlockEnd.gif       }

16InBlock.gif    
17InBlock.gif        //使用prototype类库
18InBlock.gif    Element.show(this.msgbox);
19InBlock.gif    Element.show(this.msgbuttonyes);
20InBlock.gif    Element.show(this.msgbuttonno);
21InBlock.gif    Element.hide(this.msgbuttonok);
22InBlock.gif    
23InBlock.gif    var x=0,y=0;
24InBlock.gif    x = (document.documentElement.scrollLeft || document.body.scrollLeft);
25InBlock.gif    y = (document.documentElement.scrollTop || document.body.scrollTop);
26InBlock.gif    
27ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//*一下这段这么复杂的处理方法,是为了符合最新web标准,因为在aspx页面中会默认加入
28InBlock.gif<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
29InBlock.gif新的标准中不支持document.body.clientHeight 属性,它是MSIE所有的
30InBlock.gif
31ExpandedSubBlockEnd.gif*/

32InBlock.gif    var theWidth=0,theHeight=0;
33InBlock.gif    
34InBlock.gif    if (window.innerWidth) 
35ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
36InBlock.gif      theWidth = window.innerWidth 
37InBlock.gif      theHeight = window.innerHeight 
38ExpandedSubBlockEnd.gif    }
 
39InBlock.gif    else if (document.documentElement && document.documentElement.clientWidth) 
40ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
41InBlock.gif      theWidth = document.documentElement.clientWidth 
42InBlock.gif      theHeight = document.documentElement.clientHeight 
43ExpandedSubBlockEnd.gif    }
 
44InBlock.gif    else if (document.body) 
45ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
46InBlock.gif      theWidth = document.body.clientWidth 
47InBlock.gif      theHeight = document.body.clientHeight 
48ExpandedSubBlockEnd.gif    }

49InBlock.gif    
50InBlock.gif       //做div居中处理
51InBlock.gif    this.msgbox.style.left = (theWidth  - this.msgbox.offsetWidth)/2+x;
52InBlock.gif    this.msgbox.style.top = (theHeight - this.msgbox.offsetHeight)/2+y; 
53InBlock.gif
54InBlock.gif      //绑定传入的事件
55InBlock.gif    this.msgbuttonyes.onclick = YesClick;//function(){ alert('yes');};
56InBlock.gif    this.msgbuttonno.onclick = NoClick;
57InBlock.gif      //绑定隐藏div的事件,使用prototype类库
58ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.observe(this.msgbuttonyes,"click",function()dot.gif{KMessageBox.Hide();},true);
59ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.observe(this.msgbuttonno,"click",function()dot.gif{KMessageBox.Hide();},true);
60ExpandedBlockEnd.gif}

   有了显示还需要做隐藏处理,即上面调用的KMessageBox.Hide();
  
 1 None.gifKMessageBox.Hide =  function()
 2 ExpandedBlockStart.gif ContractedBlock.gif dot.gif {
 3InBlock.gif    if (!this.msgbox ) return;
 4InBlock.gif    Element.hide(this.msgbox);
 5InBlock.gif    //detach 事件,防止IE 内存泄漏
 6ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.stopObserving(this.msgbuttonyes,"click",function()dot.gif{KMessageBox.Hide();},true)
 7ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.stopObserving(this.msgbuttonno,"click",function()dot.gif{KMessageBox.Hide();},true)
 8ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.stopObserving(this.msgbuttonok,"click",function()dot.gif{KMessageBox.Hide();},true)
 9ExpandedBlockEnd.gif}

10 None.gif

    至于模拟Alert,就可以模仿ShowConfirm来做了,so easy
   
    ok,整个MessageBox 类看起来已经像模像样了.运行一下...
   
     噫,不对,好像缺了点什么....没错,它不是ShowModal类型的...用户还可以任意点下面的页面元素.

     这个怎么模拟?

     当然还是div了...做一个整个页面大小的div覆盖在所有页面元素之上,MessageBox层之下.
    
     不过有个弊端,div不能覆盖select控件,那只好搬出iframe了..所谓道高一尺魔高一丈

   
 1 ExpandedBlockStart.gif ContractedBlock.gif function DialogModal() dot.gif
 2InBlock.gif    this.blankImgHandle = null
 3InBlock.gif    this.tags = new Array("applet", "iframe", "select","object","embed");  
 4ExpandedBlockEnd.gif}

 5 None.gif
 6 None.gif 
 7 None.gifDialogModal.Show =  function() 
 8 ExpandedBlockStart.gif ContractedBlock.gif dot.gif {     
 9InBlock.gifdebugger;
10InBlock.gif        var NameSpaceURI = "http://www.w3.org/1999/xhtml";
11InBlock.gif        this.blankImgHandle = document.createElementNS ? document.createElementNS(NameSpaceURI, "iframe") : document.createElement("iframe") ;//iframe
12InBlock.gif        this.blankImgHandle.setAttribute("id","blankImgHanldle");
13ExpandedSubBlockStart.gifContractedSubBlock.gif        with (this.blankImgHandle.style)dot.gif
14InBlock.gif            position = "absolute"; 
15InBlock.gif            left     = 0; 
16InBlock.gif            top      = (document.documentElement.scrollTop || document.body.scrollTop); 
17InBlock.gif            height   = "100%"; //这边用100%在 标准生成的aspx页面好像比起效果,去掉doctype那句就可以,所以我直接设置一个分辨率即1024X768
18InBlock.gif            width    = "100%"; 
19InBlock.gif            zIndex   = "9999"; //这个zIndex比页面所有元素大,但是要比MessageBox小,保证MessageBox 不被罩住
20InBlock.gif            filter   = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=40)"; 
21InBlock.gif            opacity  = "0.1";             
22ExpandedSubBlockEnd.gif        }
          
23InBlock.gif         
24InBlock.gif       document.getElementsByTagName("body").item(0).appendChild(this.blankImgHandle);         
25ExpandedBlockEnd.gif   }
         
26 None.gif         
27 ExpandedBlockStart.gif ContractedBlock.gifDialogModal.Close =  function() dot.gif {                
28InBlock.gif      if (this.blankImgHandle) 
29ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif
30InBlock.gif          Element.remove(this.blankImgHandle);
31InBlock.gif          this.blankImgHandle = null;
32ExpandedSubBlockEnd.gif      }
             
33ExpandedBlockEnd.gif  }

34 None.gif

    在MessageBox中Show的时候,调用DialogModal.Show,Hide的时候调用DialogModal.Hide 即ok了.

    有了上面的两个Javascript类,我们就可以很好的做服务端的封装了,取到control的dopostback函数,直接传入给ShowConfrim就可以了.
   
1 None.gif // ShowConfirm客户端事件
2 None.gif private  string JS_CONFIRM = "KMessageBox.ShowConfirm('{0}','{1}','{2}',{3},{4});return false;";
3 None.gif
4 None.gif // 获取DoPostBack事件,这边还有个难点,怎么取得客户端验证事件,目前我还没有解决
5 None.gifstrOnClickScript = "function(){" + Page.ClientScript.GetPostBackEventReference(control, "") + ";}";
6 None.gif // 注册MessageBox事件,
7 None.gif control.Attributes["onclick"] +=  string.Format(JS_CONFIRM,  this.mImgDir, caption, content, strOnClickScript, "function(){}");

源码:

代码插入比较慢,而且经常ShowDialogModal框不返回,晕死.....直接down吧: KMessageBox_Source

ContractedBlock.gif ExpandedBlockStart.gif KMessageBox.js
  1None.gif
  2ExpandedBlockStart.gifContractedBlock.gifKMessageBox = dot.gif{
  3InBlock.gif  name: "KMessageBox",
  4InBlock.gif  capiton : "消息框",
  5InBlock.gif  content: "提示消息",
  6InBlock.gif  msgbox : null,
  7InBlock.gif  msgcaptioninfo:null,
  8InBlock.gif  msgcontent:null,
  9InBlock.gif  msgContenttxtmsg:null,
 10InBlock.gif  msgbuttonyes:null,
 11InBlock.gif  msbbuttonno:null,
 12InBlock.gif  msgico:null 
 13ExpandedBlockEnd.gif}
;
 14None.gif
 15ExpandedBlockStart.gifContractedBlock.gifKMessageBox.init = function () dot.gif{
 16InBlock.gif    var msgNameSpaceURI = "http://www.w3.org/1999/xhtml";
 17InBlock.gif    
 18ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContainerID)dot.gif{ var msgContainerID= "KMessageBox"; }
 19InBlock.gif
 20ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgCaptionID)dot.gif{ var msgCaptionID= "KMessageBox_caption"; }
 21ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgCaptionInfoID)dot.gif{var msgCaptionInfoID = "KMessageBox_caption_info";}
 22ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContentID)dot.gif{ var msgContentID = "KMessageBox_content"; }
 23ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContentTxtID)dot.gif{ var msgContentTxtID= "KMessageBox_content_txt"; }
 24ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContentTxtICOID)dot.gif{var msgContentTxtICOID="KMessageBox_content_txt_ico"};
 25ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContentTxtMsgID)dot.gif{var msgContentTxtMsgID="KMessageBox_content_txt_msg"};
 26ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgButtons)dot.gif{var msgButtonsID="KMessageBox_buttons"};
 27ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgButtonYes)dot.gif{var msgButtonYesID="KMessageBox_buttons_yes"};
 28ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgButtonNo)dot.gif{var msgButtonNoID="KMessageBox_buttons_no"};    
 29ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgButtonOK)dot.gif{var msgButtonOKID="KMessageBox_buttons_ok"};    
 30InBlock.gif
 31InBlock.gif    var msgContainer = $(msgContainerID);
 32ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContainer) dot.gif{
 33InBlock.gif      msgContainer = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div");
 34InBlock.gif      msgContainer.setAttribute("id", msgContainerID);
 35InBlock.gif      msgContainer.setAttribute("style","MARGIN: 0px auto; POSITION: absolute; TEXT-ALIGN: center;");
 36InBlock.gif
 37InBlock.gif
 38InBlock.gif    var msgCaption = $(msgCaptionID);
 39InBlock.gif
 40ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgCaption)dot.gif{
 41InBlock.gif      msgCaption = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 42InBlock.gif      msgCaption.setAttribute("id",msgCaptionID);
 43InBlock.gif      Element.addClassName(msgCaption,"caption");      
 44InBlock.gif
 45InBlock.gif      
 46InBlock.gif      var msgCaptionInfo = $(msgCaptionInfoID);
 47ExpandedSubBlockStart.gifContractedSubBlock.gif      if(!msgCaptionInfo)dot.gif{
 48InBlock.gif      msgCaptionInfo = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 49InBlock.gif      msgCaptionInfo.setAttribute("id",msgCaptionInfoID);
 50InBlock.gif      Element.addClassName(msgCaptionInfo,"info");
 51InBlock.gif      msgCaption.appendChild(msgCaptionInfo);
 52ExpandedSubBlockEnd.gif      }

 53InBlock.gif      msgContainer.appendChild(msgCaption);
 54InBlock.gif      
 55ExpandedSubBlockEnd.gif    }

 56InBlock.gif    
 57InBlock.gif    var msgContent = $(msgContentID);
 58InBlock.gif
 59ExpandedSubBlockStart.gifContractedSubBlock.gif    if(!msgContent)dot.gif{
 60InBlock.gif      msgContent= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 61InBlock.gif      msgContent.setAttribute("id",msgContentID);
 62InBlock.gif      Element.addClassName(msgContent,"content");
 63InBlock.gif      
 64InBlock.gif      var msgContentTxt = $(msgContentTxtID);
 65InBlock.gif      
 66ExpandedSubBlockStart.gifContractedSubBlock.gif      if(!msgContentTxt )dot.gif{
 67InBlock.gif      msgContentTxt = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 68InBlock.gif      msgContentTxt.setAttribute("id",msgContentTxtID);
 69InBlock.gif      Element.addClassName(msgContentTxt,"txt");
 70InBlock.gif           
 71InBlock.gif      var msgContentTxtICO = $(msgContentTxtICOID);
 72InBlock.gif      if(!msgContentTxtICO)
 73ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{
 74InBlock.gif         msgContentTxtICO= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "img") : document.createElement("img") ;
 75InBlock.gif         msgContentTxtICO.setAttribute("id",msgContentTxtICOID);
 76InBlock.gif         msgContentTxtICO.setAttribute("src","icon_alarm.gif");
 77InBlock.gif         msgContentTxtICO.setAttribute("align","absMiddle");
 78InBlock.gif         msgContentTxtICO.setAttribute("style","height:52px;width:64px;background-image:url('icon_big_info.gif');");
 79InBlock.gif         msgContentTxt.appendChild(msgContentTxtICO);
 80ExpandedSubBlockEnd.gif      }

 81InBlock.gif      
 82InBlock.gif      var msgContentTxtMsg= $(msgContentTxtMsgID);
 83InBlock.gif      if(!msgContentTxtMsg)
 84ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{
 85InBlock.gif         msgContentTxtMsg= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "span") : document.createElement("span") ;
 86InBlock.gif         msgContentTxtMsg.setAttribute("id",msgContentTxtMsgID);
 87InBlock.gif         
 88InBlock.gif         msgContentTxt.appendChild(msgContentTxtMsg);
 89ExpandedSubBlockEnd.gif      }

 90InBlock.gif
 91InBlock.gif
 92InBlock.gif      var msgButtons = $(msgButtonsID);
 93InBlock.gif      if(!msgButtons)
 94ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{
 95InBlock.gif         msgButtons = document.createElementNS ? document.createElementNS(msgNameSpaceURI, "div") : document.createElement("div") ;
 96InBlock.gif         msgButtons.setAttribute("id",msgButtonsID);
 97InBlock.gif         Element.addClassName(msgButtons,"btnlist");
 98InBlock.gif         var msgButtonYes = $(msgButtonYesID);
 99InBlock.gif          if(!msgButtonYes)
100ExpandedSubBlockStart.gifContractedSubBlock.gif          dot.gif{
101InBlock.gif            msgButtonYes= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
102InBlock.gif            msgButtonYes.setAttribute("id",msgButtonYesID);
103InBlock.gif            msgButtonYes.setAttribute("type","button");
104InBlock.gif            msgButtonYes.setAttribute("value","YES");
105InBlock.gif            Element.addClassName(msgButtonYes,"input_set");
106InBlock.gif                    
107InBlock.gif            msgButtons.appendChild(msgButtonYes);             
108ExpandedSubBlockEnd.gif         }

109InBlock.gif
110InBlock.gif         var msgButtonNo = $(msgButtonNoID);
111InBlock.gif          if(!msgButtonNo)
112ExpandedSubBlockStart.gifContractedSubBlock.gif          dot.gif{
113InBlock.gif            msgButtonNo= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
114InBlock.gif            msgButtonNo.setAttribute("id",msgButtonNoID);
115InBlock.gif            msgButtonNo.setAttribute("type","button");
116InBlock.gif            msgButtonNo.setAttribute("value","NO");
117InBlock.gif            Element.addClassName(msgButtonNo,"input_set");
118InBlock.gif            
119InBlock.gif            msgButtons.appendChild(msgButtonNo); 
120InBlock.gif            
121ExpandedSubBlockEnd.gif         }

122InBlock.gif         
123InBlock.gif         var msgButtonOK= $(msgButtonOKID);
124InBlock.gif          if(!msgButtonOK)
125ExpandedSubBlockStart.gifContractedSubBlock.gif          dot.gif{
126InBlock.gif            msgButtonOK= document.createElementNS ? document.createElementNS(msgNameSpaceURI, "input") : document.createElement("input") ;
127InBlock.gif            msgButtonOK.setAttribute("id",msgButtonOKID);
128InBlock.gif            msgButtonOK.setAttribute("type","button");
129InBlock.gif            msgButtonOK.setAttribute("value","OK");
130InBlock.gif            Element.addClassName(msgButtonOK,"input_set");
131InBlock.gif            
132InBlock.gif            msgButtons.appendChild(msgButtonOK); 
133InBlock.gif            
134ExpandedSubBlockEnd.gif         }

135InBlock.gif
136InBlock.gif
137InBlock.gif         msgContentTxt.appendChild(msgButtons);
138ExpandedSubBlockEnd.gif      }

139InBlock.gif      
140InBlock.gif      msgContent.appendChild(msgContentTxt);
141ExpandedSubBlockEnd.gif      }

142InBlock.gif
143InBlock.gif      
144InBlock.gif      msgContainer.appendChild(msgContent);
145ExpandedSubBlockEnd.gif    }

146InBlock.gif
147InBlock.gif     document.getElementsByTagName("body").item(0).appendChild(msgContainer);
148ExpandedSubBlockEnd.gif    }

149InBlock.gif       
150InBlock.gif    this.msgbox = $(this.name);
151InBlock.gif    this.msgcaptioninfo = $(msgCaptionInfoID);
152InBlock.gif    this.msgContenttxtmsg= $(msgContentTxtMsgID);
153InBlock.gif    this.msgbuttonyes = $(msgButtonYesID);
154InBlock.gif    this.msgbuttonno = $(msgButtonNoID);
155InBlock.gif    this.msgbuttonok = $(msgButtonOKID);
156InBlock.gif    this.msgico = $(msgContentTxtICOID);
157InBlock.gif    Element.hide(this.msgbox);
158InBlock.gif   
159ExpandedBlockEnd.gif}

160None.gif
161ExpandedBlockStart.gifContractedBlock.gifKMessageBox.ShowConfirm = function (imgdir,caption,msg,YesClick,NoClick) dot.gif{
162InBlock.gif    
163InBlock.gif    if (!this.msgbox ) return;
164InBlock.gif    //alert(document.body.style.overflowY);
165InBlock.gif    DialogModal.Show();
166InBlock.gif    
167InBlock.gif    this.msgcaptioninfo.innerHTML = caption;
168InBlock.gif    this.msgContenttxtmsg.innerHTML = msg;
169InBlock.gif    if(imgdir != "")
170ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
171InBlock.gif       this.msgico.setAttribute("src",imgdir+"/kinnsoft_client/KMessageBox/icon_alarm.gif");
172ExpandedSubBlockEnd.gif    }

173InBlock.gif    else
174ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
175InBlock.gif       this.msgico.setAttribute("src","/kinnsoft_client/KMessageBox/icon_alarm.gif");
176ExpandedSubBlockEnd.gif    }

177InBlock.gif    
178InBlock.gif    Element.show(this.msgbox);
179InBlock.gif    Element.show(this.msgbuttonyes);
180InBlock.gif    Element.show(this.msgbuttonno);
181InBlock.gif    Element.hide(this.msgbuttonok);
182InBlock.gif    
183InBlock.gif    var x=0,y=0;
184InBlock.gif    x = (document.documentElement.scrollLeft || document.body.scrollLeft);
185InBlock.gif    y = (document.documentElement.scrollTop || document.body.scrollTop);
186InBlock.gif    
187InBlock.gif    var theWidth=0,theHeight=0;
188InBlock.gif    
189InBlock.gif    if (window.innerWidth) 
190ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
191InBlock.gif      theWidth = window.innerWidth 
192InBlock.gif      theHeight = window.innerHeight 
193ExpandedSubBlockEnd.gif    }
 
194InBlock.gif    else if (document.documentElement && document.documentElement.clientWidth) 
195ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
196InBlock.gif      theWidth = document.documentElement.clientWidth 
197InBlock.gif      theHeight = document.documentElement.clientHeight 
198ExpandedSubBlockEnd.gif    }
 
199InBlock.gif    else if (document.body) 
200ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
201InBlock.gif      theWidth = document.body.clientWidth 
202InBlock.gif      theHeight = document.body.clientHeight 
203ExpandedSubBlockEnd.gif    }

204InBlock.gif    
205InBlock.gif    this.msgbox.style.left = (theWidth  - this.msgbox.offsetWidth)/2+x;
206InBlock.gif    this.msgbox.style.top = (theHeight - this.msgbox.offsetHeight)/2+y; 
207InBlock.gif
208InBlock.gif    this.msgbuttonyes.onclick = YesClick;//function(){ alert('yes');};
209InBlock.gif    this.msgbuttonno.onclick = NoClick;
210InBlock.gif
211ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.observe(this.msgbuttonyes,"click",function()dot.gif{KMessageBox.Hide();},true);
212ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.observe(this.msgbuttonno,"click",function()dot.gif{KMessageBox.Hide();},true);
213ExpandedBlockEnd.gif}

214None.gif
215ExpandedBlockStart.gifContractedBlock.gifKMessageBox.ShowInfo = function (imgdir,caption,msg) dot.gif{
216InBlock.gif    
217InBlock.gif    if (!this.msgbox ) return;    
218InBlock.gif    DialogModal.Show();
219InBlock.gif    
220InBlock.gif    if(imgdir != "")
221ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
222InBlock.gif       this.msgico.setAttribute("src",imgdir+"/kinnsoft_client/KMessageBox/icon_big_info.gif");
223ExpandedSubBlockEnd.gif    }

224InBlock.gif    else
225ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
226InBlock.gif       this.msgico.setAttribute("src","/kinnsoft_client/KMessageBox/icon_big_info.gif");
227ExpandedSubBlockEnd.gif    }

228InBlock.gif    
229InBlock.gif    this.msgcaptioninfo.innerHTML = caption;
230InBlock.gif    this.msgContenttxtmsg.innerHTML = msg;
231InBlock.gif    Element.show(this.msgbox);
232InBlock.gif    Element.show(this.msgbuttonok);
233InBlock.gif    Element.hide(this.msgbuttonyes);
234InBlock.gif    Element.hide(this.msgbuttonno);
235InBlock.gif    
236InBlock.gif    var x=0,y=0;
237InBlock.gif    x = (document.documentElement.scrollLeft || document.body.scrollLeft);
238InBlock.gif    y = (document.documentElement.scrollTop || document.body.scrollTop);
239InBlock.gif    
240InBlock.gif    var theWidth=0,theHeight=0;
241InBlock.gif    
242InBlock.gif    if (window.innerWidth) 
243ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
244InBlock.gif      theWidth = window.innerWidth 
245InBlock.gif      theHeight = window.innerHeight 
246ExpandedSubBlockEnd.gif    }
 
247InBlock.gif    else if (document.documentElement && document.documentElement.clientWidth) 
248ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
249InBlock.gif      theWidth = document.documentElement.clientWidth 
250InBlock.gif      theHeight = document.documentElement.clientHeight 
251ExpandedSubBlockEnd.gif    }
 
252InBlock.gif    else if (document.body) 
253ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
254InBlock.gif      theWidth = document.body.clientWidth 
255InBlock.gif      theHeight = document.body.clientHeight 
256ExpandedSubBlockEnd.gif    }

257InBlock.gif    
258InBlock.gif    this.msgbox.style.left = (theWidth  - this.msgbox.offsetWidth)/2+x;
259InBlock.gif    this.msgbox.style.top = (theHeight - this.msgbox.offsetHeight)/2+y; 
260InBlock.gif
261InBlock.gif    
262ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.observe(this.msgbuttonok,"click",function()dot.gif{KMessageBox.Hide();},true);
263ExpandedBlockEnd.gif}

264None.gif
265None.gif
266None.gifKMessageBox.Hide = function()
267ExpandedBlockStart.gifContractedBlock.gifdot.gif{
268InBlock.gif    if (!this.msgbox ) return;
269InBlock.gif    Element.hide(this.msgbox);
270InBlock.gif    DialogModal.Close();
271ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.stopObserving(this.msgbuttonyes,"click",function()dot.gif{KMessageBox.Hide();},true)
272ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.stopObserving(this.msgbuttonno,"click",function()dot.gif{KMessageBox.Hide();},true)
273ExpandedSubBlockStart.gifContractedSubBlock.gif    Event.stopObserving(this.msgbuttonok,"click",function()dot.gif{KMessageBox.Hide();},true)
274ExpandedBlockEnd.gif}

275None.gif
276None.gif
277ExpandedBlockStart.gifContractedBlock.giffunction DialogModal()dot.gif
278InBlock.gif    this.blankImgHandle = null
279InBlock.gif    this.tags = new Array("applet", "iframe", "select","object","embed");  
280ExpandedBlockEnd.gif}

281None.gif
282None.gif 
283None.gifDialogModal.Show = function() 
284ExpandedBlockStart.gifContractedBlock.gifdot.gif{     
285InBlock.gifdebugger;
286InBlock.gif        var NameSpaceURI = "http://www.w3.org/1999/xhtml";
287InBlock.gif        this.blankImgHandle = document.createElementNS ? document.createElementNS(NameSpaceURI, "iframe") : document.createElement("iframe") ;//iframe
288InBlock.gif        this.blankImgHandle.setAttribute("id","blankImgHanldle");
289ExpandedSubBlockStart.gifContractedSubBlock.gif        with (this.blankImgHandle.style)dot.gif
290InBlock.gif            position = "absolute"; 
291InBlock.gif            left     = 0; 
292InBlock.gif            top      = (document.documentElement.scrollTop || document.body.scrollTop); 
293InBlock.gif            height   = "100%"; 
294InBlock.gif            width    = "100%"; 
295InBlock.gif            zIndex   = "9999"; 
296InBlock.gif            filter   = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=40)"; 
297InBlock.gif            opacity  = "0.1";             
298ExpandedSubBlockEnd.gif        }
          
299InBlock.gif         
300InBlock.gif       document.getElementsByTagName("body").item(0).appendChild(this.blankImgHandle);         
301ExpandedBlockEnd.gif   }
         
302None.gif         
303ExpandedBlockStart.gifContractedBlock.gifDialogModal.Close = function()dot.gif{                
304InBlock.gif      if (this.blankImgHandle) 
305ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif
306InBlock.gif          Element.remove(this.blankImgHandle);
307InBlock.gif          this.blankImgHandle = null;
308ExpandedSubBlockEnd.gif      }
             
309ExpandedBlockEnd.gif  }

310None.gif
311None.gif
312ExpandedBlockStart.gifContractedBlock.gifEvent.observe(window, 'load', function(e)dot.gif{KMessageBox.init();}false);
313None.gifEvent.observe(window, 'unload', Event.unloadCache, false);

 

ContractedBlock.gif ExpandedBlockStart.gif KMessageBox.css
 1None.gif
 2None.gif#KMessageBox
 3ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{
 4InBlock.gif margin:0px auto;
 5InBlock.gif width :398px;
 6InBlock.gif height:188px;
 7InBlock.gif border:1px solid #498AC2;
 8InBlock.gif font-size:9pt;
 9InBlock.gif position:absolute;
10InBlock.gif z-index: 10000 ;
11ExpandedBlockEnd.gif}

12None.gif
13None.gif
14None.gif#KMessageBox .caption
15ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{
16InBlock.giffont-family:'tahoma';
17InBlock.giffont-size:8pt;
18InBlock.gifbackground:#45A0EE url('alter_bar.gif') no-repeat;
19InBlock.gifheight:28px;
20InBlock.giftext-align:left;
21ExpandedBlockEnd.gif}

22None.gif#KMessageBox .info
23ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{
24InBlock.giffloat:left;
25InBlock.gifcolor:#fff;
26InBlock.giffont-weight:bold;
27InBlock.gifmargin:8px 0 0 8px;
28ExpandedBlockEnd.gif}

29None.gif#KMessageBox .content
30ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{
31InBlock.giffont-family:'tahoma';
32InBlock.giffont-size:8pt;
33InBlock.gifwidth:396px;
34InBlock.gifword-break:break-all;
35InBlock.gifheight:157px;
36InBlock.gifborder:1px solid #fff;
37InBlock.gifbackground:#fff url('alter_bg.gif') repeat-x;
38ExpandedBlockEnd.gif}

39None.gif#KMessageBox .txt
40ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{
41InBlock.gifmargin-top:25px;
42InBlock.giftext-align:center;
43InBlock.gifcolor:#327FC6;
44InBlock.gifpadding:0 12px;
45InBlock.gifline-height:22px;
46ExpandedBlockEnd.gif}

47None.gif.txt
48ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{
49InBlock.giffont-family:tahoma;
50InBlock.giffont-size:11px;
51InBlock.giffont-weight:normal;
52ExpandedBlockEnd.gif}

53ExpandedBlockStart.gifContractedBlock.gifimg{dot.gif}{border:0}
54None.gif#KMessageBox .btnlist
55ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{margin-top:30px;text-align:center;}
56None.gif
57None.gif#KMessageBox .input_set
58ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{
59InBlock.gifborder-style: none;
60InBlock.gif    border-color: inherit;
61InBlock.gif    border-width: 0;
62InBlock.gif    font-size:9pt;    width:63px;    height:22px;background:url('compose.gif') no-repeat -154px -22px;
63ExpandedBlockEnd.gif}

64None.gif.input_set
65ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{
66InBlock.gif    width:50%;
67InBlock.gif    height:17px!important;height :21px;
68InBlock.gif    border:1px solid #7F9DB9;
69InBlock.gif    padding:3px 2px 0 2px!important;
70ExpandedSubBlockStart.gifContractedSubBlock.gif    padding /**//**/:3px 2px 1px 2px;
71InBlock.gif    color:#494949;
72ExpandedBlockEnd.gif}

73None.gif
74None.gif
75None.gif.input_Alist
76ExpandedBlockStart.gifContractedBlock.gif{dot.gif}{  
77InBlock.gif    border-style : none;
78InBlock.gif    border-color: inherit;
79InBlock.gif    border-width: 0;
80InBlock.gif    width:85px;    height:22px;background:#fff url('input_bg_alist.gif') no-repeat;
81InBlock.gif    float:left;                
82ExpandedBlockEnd.gif}


本文转自浪子博客园博客,原文链接:http://www.cnblogs.com/walkingboy/archive/2006/08/10/Cilent_KMessageBox.html,如需转载请自行联系原作者
目录
相关文章
|
8天前
|
前端开发 JavaScript
使用JavaScript实现复杂功能:构建一个自定义的拖拽功能
使用JavaScript实现复杂功能:构建一个自定义的拖拽功能
|
6月前
uniapp自定义过滤器filter.js
uniapp自定义过滤器filter.js
65 0
|
7月前
|
JSON JavaScript 前端开发
JavaScript的自定义对象
JavaScript的自定义对象
|
4月前
|
存储 设计模式 监控
如何构建自定义 Node.js 事件发射器
如何构建自定义 Node.js 事件发射器
469 2
|
4月前
|
JavaScript 测试技术
【sgGoogleTranslate】自定义组件:基于Vue.js用谷歌Google Translate翻译插件实现网站多国语言开发
【sgGoogleTranslate】自定义组件:基于Vue.js用谷歌Google Translate翻译插件实现网站多国语言开发
|
3月前
|
存储 JavaScript 前端开发
JavaScript 自定义对象 及 new()原理与实现 如何完整地手写实现new
JavaScript 自定义对象 及 new()原理与实现 如何完整地手写实现new
59 0
|
4月前
|
JavaScript 前端开发 C++
如何构建自定义 Node.js 事件发射器
如何构建自定义 Node.js 事件发射器
32 2
|
4月前
|
前端开发 JavaScript
前端用原生js编辑文件内容→创建生成文件(格式可以自定义)→下载文件
前端用原生js编辑文件内容→创建生成文件(格式可以自定义)→下载文件
|
7月前
|
JavaScript
js字体标红-高亮-自定义高亮-搜索高亮
js字体标红-高亮-自定义高亮-搜索高亮