Javascript imitates the msgbox prompt result code

Source: Internet
Author: User

Copy codeThe Code is as follows:
// Former Author: http://www.moozi.net
// Modify: hh13774978@126.com, rayking
Function $ (str ){
Return document. getElementById (str );
}
Function _ (str ){
Return document. getElementsByTagName (str );
}
Function msg (boxtitle, boxtype, boxwidth, msg, url ){
$ ("Msg_div_main"). style. width = boxwidth;
$ ("Msg_div_main"). style. left = (_ ("body") [0]. clientWidth-boxwidth)/2;
$ ("Msg_div_main"). style. top = (_ ("body") [0]. clientHeight-220)/2;
Var msg_div_main_but_tmp = "<br/>"
+ "<Button class = 'msg _ div_main_but 'id = 'msg _ div_main_but '"
+ "Onclick = \" msg_close_tmp_biyuan (); "+ url +" \ "> confirm </button> ";
Switch (boxtype * 1 ){
Case 1:
$ ("Msg_div_main_content"). innerHTML = msg + msg_div_main_but_tmp;
// $ ("Msg_div_main_but"). focus ();
Break;
Case 2:
$ ("Msg_div_main_content"). innerHTML = msg + msg_div_main_but_tmp
+ "<Button class = 'msg _ div_main_but '"
+ "Onclick = 'msg _ close_tmp_biyuan (); '> cancel </button> ";
// $ ("Msg_div_main_but"). focus ();
Break;
Case 3:
$ ("Msg_div_main_content"). innerHTML = msg;
Break;
Defualt:
$ ("Msg_div_main_content"). innerHTML = msg;
Break;
}
$ ("Msg_div_main_title"). innerHTML = boxtitle;
$ ("Msg_div_main"). style. zIndex = 200;
$ ("Msg_div_main"). style. display = "";
If (document. all) {// IE
If (! $ ("Msg_div_all_Iframe "))
{
Document. body. appendChild (document. createElement ("<iframe id = 'msg _ div_all_Iframe 'style = 'display: none;'> </iframe> "));
}
$ ("Msg_div_all"). style. zIndex = 100;
$ ("Msg_div_all"). style. display = "";
$ ("Msg_div_all"). oncontextmenu = function ()
{
Return false;
}
$ ("Msg_div_all_Iframe"). style. zIndex = 99;
$ ("Msg_div_all_Iframe"). style. display = "";
$ ("Msg_div_all_Iframe"). oncontextmenu = function ()
{
Return false;
}
} Else {
$ ("Msg_div_all"). style. zIndex = 100;
$ ("Msg_div_all"). style. display = "";
$ ("Msg_div_all"). oncontextmenu = function ()
{
Return false;
}
}
$ ("Msg_div_main"). oncontextmenu = function (){
Return false;
}
}
Function msg_close_tmp_biyuan (){
$ ('Msg _ div_all '). style. display = 'none ';
$ ('Msg _ div_main '). style. display = 'none ';
If (document. all ){
$ ('Msg _ div_all_Iframe '). style. display = 'none ';}
}
// Move the code in the Add dialog box
/* Drag the mouse */
Var oDrag = "";
Var ox, oy, nx, ny, dy, dx;
Function drag (e, o ){
Var e = e? E: event;
Var mouseD = document. all? 1: 0;
If (e. button = mouseD)
{
If (o. parentNode)
{
ODrag = o. parentNode;
}
Else {oDrag = o ;}
Ox = e. clientX;
Oy = e. clientY;
}
}
Function dragPro (e ){
If (oDrag! = "")
{
// Var obj = document. getElementById ("msg"); // The drag id
Var obj = oDrag; // drag id
Var e = e? E: event;
Obj. style. position = 'absolute ';
Dx = parseInt (obj. style. left );
Dy = parseInt (obj. style. top );
If (isNaN (dx) {dx = 0 ;}
If (isNaN (dy) {dy = 0 ;}
Nx = e. clientX;
Ny = e. clientY;
Obj. style. left = (dx + (nx-ox) + "px ";
Obj. style. top = (dy + (ny-oy) + "px ";
Ox = nx;
Oy = ny;
}
}
Document. onmouseup = function () {oDrag = "";}
Document. onmousemove = function (event) {dragPro (event );}
Document. writeln ("<style type = 'text/css '>"
+ "# Msg_div_all, # msg_div_all_Iframe {width: 100%; height: 100%; position: absolute; filter: Alpha (opacity = 70); opacity: 0.7; background: # EFEFEF ;}"
+ "# Msg_div_main {position: absolute ;}"
+ "# Msg_div_main_title {font-size: 12px; color: # 2C71AF; font-family: verdana; cursor: default ;}"
+ "# Msg_div_main_content {font-size: 14px; color: # 2C71AF; padding-left: 8px ;}"
+ ". Msg_div_main_but {background: url (img/buttonbg.gif); width: 65px; heimpaired: 20px; border: none; padding-top: 3px; font-size: 12px ;}"
+ "</Style>"
+ "<Div id = 'msg _ div_all 'style = 'display: none;'> </div>"
+ ""
+ "<Div id = 'msg _ div_main 'style = 'display: none;'>"
+ "<Table width = '000000' height = '29' border = '0' cellspacing = '0' cellpadding = '0' onmousedown = 'drag (event, this) '>"
+ "<Tr>"
+ "<Td width = '25'> </td> <td background = 'img/bg_02.gif 'width = '3'> </td>"
+ "<Td background = 'img/bg_02.gif 'msg_forid = 'msg _ div_main' id = 'msg _ div_main_title '> </td>"
+ "<Td background = 'img/bg_02.gif 'align = 'right' style = 'padding-top: 4px'>"
+ "+ "OnMouseover = \" this. src = 'img/bg_13.gif '\""
+ "OnMouseout = \" this. src = 'img/bg_05.gif '\ "onMouseup = 'msg _ close_tmp_biyuan ();'"
+ "OnMousedown = \" this. src = 'img/bg_18.gif '\ "> </td>"
+ "<Td width = '6'> </td>"
+ "</Tr>"
+ "</Table>"
+ "<Table width = '000000' border = '0' cellspacing = '0' cellpadding = '0'>"
+ "<Tr>"
+ "<Td width = '3' background = 'img/bg_07.gif '> </td>"
+ "<Td bgcolor = '# F7F7F7' align = 'center'> <br/> <span id = 'msg _ div_main_content '> </span> <br/> <br /> </td>"
+ "<Td width = '3' background = 'img/bg_08.gif '> </td>"
+ "</Tr>"
+ "<Tr>"
+ "<Td width = '3' height = '3'> </td>"
+ "<Td background = 'img/bg_11.gif '> </td>"
+ "<Td width = '3' height = '3'> </td>"
+ "</Tr>"
+ "</Table>"
+ "</Div> ");

Online Demo
Package download

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.