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>