Settimeout prompt function not defined

Source: Internet
Author: User

// Time var endtime = '20140901'; var Account = ''; RemainTimes (); function RemainTimes () {var iHour, iMinute, iSecond; var sHour = "", sMinute = "", sSecond = "", sTime = "; if (endtime> = 0) {iHour = parseInt (endtime/3600) % 24 ); if (iHour> 0) {sHour = iHour + "Hour";} iMinute = parseInt (endtime/60) % 60); if (iMinute> 0) {sMinute = iMinute + "min";} iSecond = parseInt (endtime % 60); if (iSecond> = 0) {sSecond = iSeco Nd + "seconds" ;}// point-to-point warning if (sHour = "") {}else {}stime = sHour + sMinute + sSecond; if (endtime = 0) {clearTimeout (Account); sTime = "it's time! ";}Else {Account = setTimeout (" RemainTimes () ", 1000);} endtime = endtime-1;} else {sTime =" the countdown is over! ";}$ (" # Remaintime "). text (sTime );}


This is the original code and will prompt that the RemainTimes is not defined. The solution is not to write the function directly in settimeout, but to use the anonymous function method.


// Time var endtime = '20140901'; var Account = ''; RemainTimes (); function RemainTimes () {var iHour, iMinute, iSecond; var sHour = "", sMinute = "", sSecond = "", sTime = "; if (endtime> = 0) {iHour = parseInt (endtime/3600) % 24 ); if (iHour> 0) {sHour = iHour + "Hour";} iMinute = parseInt (endtime/60) % 60); if (iMinute> 0) {sMinute = iMinute + "min";} iSecond = parseInt (endtime % 60); if (iSecond> = 0) {sSecond = iSeco Nd + "seconds" ;}// point-to-point warning if (sHour = "") {}else {}stime = sHour + sMinute + sSecond; if (endtime = 0) {clearTimeout (Account); sTime = "it's time! ";}Else {Account = setTimeout (function () {RemainTimes () ;}, 1000) ;}endtime = endtime-1 ;}else {sTime =" the countdown is over! ";}$ (" # Remaintime "). text (sTime );}


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.