Jquery pop-up window Prompt window code sharing

Source: Internet
Author: User

Jquery pop-up window Prompt window code sharing

The pop-up window prompt plug-in created by jquery contains multiple modes. For more information about the functions with receipt function values, see

The Code is as follows:

<Script type = "text/javascript" src = "js/jquery-1.7.1.min.js"> </script>

<! -- [If IE 6]>

<Script type = "text/javascript" src = "js/iepngfix_tilebg.js"> </script>

<! [Endif] -->

<Script type = "text/javascript">

Function position (elem, l, t ){

Var isIE6 =! -[1,] &! Window. XMLHttpRequest;

If (isIE6 ){

Var style = elem. style,

Dom = '(document.doc umentElement )',

Left = l-document.doc umentElement. scrollLeft,

Top = t-document.doc umentElement. scrollTop;

Style. position = 'absolute ';

Style. removeExpression ('left ');

Style. removeExpression ('top ');

Style. setExpression ('left', 'eval ('+ dom +'. scrollLeft + '+ left +') + "px "');

Style. setExpression ('top', 'eval ('+ dom +'. scrollTop + '+ top +') + "px "');

} Else {

Elem. style. position = 'fixed ';

}

}

Function scscms_alert (msg, sign, OK, can ){

Var c _ = false; // whether the window has been closed to resolve the conflict between automatic close and manual close

Sign = sign | "";

Var s = "<div id = 'mask _ lay'> </div> <div id = 'scs _ alert '> <div id = 'alert _ top'> </ div> <div id = 'alert _ bg '> <table width = '000000' align = 'center' border = '0' cellspacing = '0' cellpadding = '1'> <tr> ";

If (sign! = "") S + = "<td width = '45'> <div id = 'inco _" + sign + "'> </div> </td> ";

S + = "<td id = 'alert _ txt '>" + msg + "</td> </tr> </table> ";

If (sign = "confirm "){

S + = "<a href = 'javascript: void (0) 'id = 'Confirm _ OK'> confirm </a> <a href = 'javascript: void (0) 'id = 'Confirm _ cancel '> cancel </a> ";

} Else {

S + = "<a href = 'javascript: void (0) 'id = 'alert _ OK'> confirm </a>"

}

S + = "</div> <div id = 'alert _ foot'> </div> ";

$ ("Body"). append (s );

$ ("# Scs_alert" ).css ("margin-top",-($ ("# scs_alert "). height ()/2) + "px"); // center it vertically

$ ("# Scs_alert"). focus (); // obtain the focus, in case the function cannot be triggered after the carriage return.

Position (document. getElementById ('mask _ lay'), 0, 0 );

Position (document. getElementById ('scs _ alert '), $ (window). width ()/2, $ (window). height ()/2 );

If (typeof can = "number "){

// Timed close prompt

SetTimeout (function (){

Close_info ();

}, Can * 1000 );

}

Function close_info (){

// Close the prompt window

If (! C _){

$ ("# Mask_layer"). fadeOut ("fast", function (){

$ ("# Scs_alert"). remove ();

$ (This). remove ();

});

C _ = true;

}

}

$ ("# Alert_ OK"). click (function (){

Close_info ();

If (typeof (OK) = "function") OK ();

});

$ ("# Confirm_ OK"). click (function (){

Close_info ();

If (typeof (OK) = "function") OK ();

});

$ ("# Confirm_cancel"). click (function (){

Close_info ();

If (typeof (can) = "function") can ();

});

Function modal_key (e ){

E = e | event;

Close_info ();

Var code = e. which | event. keyCode;

If (code = 13 | code = 32) {if (typeof (OK) = "function") OK ()}

If (code = 27) {if (typeof (can) = "function") can ()}

}

// Bind the carriage return and ESC keys

If (document. attachEvent)

Document. attachEvent ("onkeydown", modal_key );

Else

Document. addEventListener ("keydown", modal_key, true );

}

// ================================================================== Test function = = //

Function test1 (){

Scscms_alert ("Default Message ");

}

Function test2 (){

Scscms_alert ("Success prompt", "OK ");

}

Function test3 (){

Scscms_alert ("Callback function after successful prompt", "OK", function () {alert ("Callback successful! ")});

}

Function test4 (){

Scscms_alert ("error message", "error ");

}

Function test5 (){

Scscms_alert ("error message", "error", function () {alert ("Oh! No! ")});

}

Function test6 (){

Scscms_alert ("warning message", "warn ");

}

Function test7 (){

Scscms_alert ("warning message", "warn", function () {alert ("Oh! Warning! ")});

}

Function test8 (){

Scscms_alert ("do you like this message? "," Confirm ", function (){

Scscms_alert ("You liked it. Thank you! "," OK ");

}, Function (){

Scscms_alert ("You have chosen dislike, Khan! "," Error ");

});

}

Function test9 (){

Scscms_alert ("automatically disable this information 3 seconds later", "OK", "", 3 );

}

Function test10 (){

Scscms_alert. "," Confirm ", function () {alert (" OK to call back! ")}, 3 );

}

</Script>

 

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.