Message Implementation when the Jquery website saves information, and disappears automatically after the prompt

Source: Internet
Author: User

Most websites now have verification and message prompts: In order to provide a better user experience, you do not need to use alert to prompt the message. jQuery prompts the message to disappear automatically, for example:

Css:


#tip_message {z-index: 9999;position: fixed;left: 0;top: 40%;text-align: center;width: 100%;}#tip_message span {background-color: #03C440;opacity: .8;padding: 20px 50px;border-radius: 5px;text-align: center;color: #fff;font-size: 20px;}#tip_message span.error {background-color: #EAA000;}

The javascript code is as follows:

<Script type = "text/javascript" src = "js/jquery-1.9.1.min.js"> </script> <script type = "text/javascript"> $ (document ). ready (function () {// message indicating success ShowSuccessMessage = function (message, life) {var time = 50000; if (! Life) {time = life;} if ($ ("# tip_message "). text (). length> 0) {var msg = "" + message + ""; $ ("# tip_message "). empty (). append (msg);} else {var msg = "" + message + ""; $ ("body "). append (msg) ;}$ ("# tip_message "). fadeIn (time); setTimeout ($ ("# tip_message "). fadeOut (time), time) ;}; // the error message ShowErrorMessage = function (message, life) {ShowSuccessMessage (message, life); $ ("# tip_message span "). addClass ("error ") ;}; ShowMessage ("Hello success! ", 5000); // The second parameter life indicates the display time of the message ShowErrorMessage (" Hello error! ", 50000) ;}); </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.