في الآونة الأخيرة ، نقوم بمشروع اليانصيب للترتيب خمسة. كل فترة لديها فترة شراء يانصيب. هذا هو عندما يفتح المستخدم هذا الترتيب الخمس صفحات ، سيتم إرسال محصوله من الخادم (الوقت المتبقي قبل نهاية فترة اليانصيب هذه) ، وبعد ذلك سيتم تقديم هذه المرة إلى المستخدم على جانب العميل ، مما يسمح للمستخدم بالحصول على الوقت المتبقي من فترة اليانصيب هذه.
مبدأ التنفيذ بسيط للغاية. لن أخوض في التفاصيل هنا. قم بتشغيل الكود التالي لعرض العرض التوضيحي:
<! doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html ؛ charset = gbk"/> <title> index </title> <type> <sytive> "text/css"> em {color:#f00 ؛ type = "text/javaScript"> var thetime = function () {this.init.apply (this ، mations) ؛} ؛ thetime.prototype = {init: function (obj) {var that = this ؛ obj = that.buildparam (obj) ؛ that.callback = obj.callback ؛ var container = that.container = document.getElementById (obj.container) ؛ container.innerhtml = '<em> </em> ساعة <em> </em> دقيقة <em> </em> Seconds' ؛ var hourspace = that.hourspace = container.getElementSbyTagName ('em') [0] ؛ var minotpace = that.minutespace = container.getElementSbyTagName ('em') [1] ؛ var secondspace = that.secondspace = container.getElementSbyTagName ('em') [2] ؛ if (obj.Remaintime == 0) {that.resettime () ؛ يعود؛ } that.hours = math.floor (obj.remaintime/3600) ؛ that._remainder1 = obj.remaintime ٪ 3600 ؛ that.minutes = math.floor (that._remainder1/60) ؛ that.Seconds = that._remainder1 ٪ 60 ؛ var timer = that.timer = setInterval (function () {that.rendertime.apply (that) ؛} ، 1000) ؛ } ، buildparam: function (obj) {obj = {// container هي حاوية المعرف لعقدة DOM: obj.container || "حاوية" ، تبقى: العدد (OBJ.Remaintime) || 0 ، // رد الاتصال بعد العد التنازلي يكتمل رد الاتصال: obj.callback || وظيفة جديدة} ؛ إرجاع OBJ ؛ } ، resettime: function () {var that = this ؛ that.container.innerhtml = "easulined" ؛ } ، // refrite time rendertime: function () {// debugger ؛ var that = هذا ؛ if (that.seconds> 0) {that.Seconds-- ؛ } آخر {that.Seconds = 59 ؛ if (that.minutes> 0) {that.minutes-- ؛ } آخر {that.minutes = 59 ؛ if (that.hours> 0) {that.hours-- ؛ }}} // الاستعداد إذا (that.hours == 0 && that.minutes == 0 && that.seconds == 0) {// تنفيذ رد الاتصال that._callback () ؛ } var bithandle = that.bithandle ؛ var _hour = bithandle (that.hours) ؛ var _minute = bithandle (that.minutes) ؛ var _second = bithandle (that.Seconds) ؛ that.hourspace.innerhtml = _hour ؛ that.minutespace.innerhtml = _minute ؛ that.secondspace.innerhtml = _second ؛ } ، // لمعالجة البت ، تأكد من إرجاع رقم مكون من رقمين Bithandle: function (num) {var str = num.toString () ؛ if (str.length <2) {str = 0 + str ؛ } إرجاع str ؛ } ، _callback: function () {var that = this ؛ ClearInterval (that.timer) ؛ that.callback () ؛ } ؛