Often encountered the effect of the page activity countdown, So wrote a JS countdown method, pulled out, directly quoted Common.js file can be.
Common.js file:
varCountdown = { " Now":NewDate (),"Lefttime": function (t) {//T parameter format: 2015/2/11 10:08:51 varDT =NewDate (t); varnow = This. Now; vardistime = DT-Now ; if(Distime <=0) { return; } varDays = parseint (Distime/( +*3600* -)); varLeftday = parseint (distime% ( +*3600* -)); varHours = parseint (Leftday/( +*3600)); varLefthour = parseint (leftday% ( +*3600)); varminutes = parseint (Lefthour/( +* -)); varLeftminute = parseint (lefthour% ( +* -)); varseconds = parseint (Leftminute/( +)); varShowday = (Days <Ten) ? ('0'+days.tostring ()): Days.tostring (); varShowhour = (Hours <Ten) ? ('0'+hours.tostring ()): Hours.tostring (); varShowminute = (Minutes <Ten) ? ('0'+minutes.tostring ()): Minutes.tostring (); varShowsecond = (Seconds <Ten) ? ('0'+seconds.tostring ()): Seconds.tostring (); returnShowday +"|"+ Showhour +"|"+ Showminute +"|"+Showsecond; }};
Pages to use:
<script src="@Url. Content ("~/common.js")"Type="Text/javascript"></script>"Text/javascript">varTime ="2015/3/11 10:01:15"; varValue =Countdown.lefttime (time); varTimes = Value.split ('|'); Alert (times[0] +"days"+ times[1] +"when"+ times[2] +"points"+ times[3] +"seconds");</script>
=============================================================================================
Additional JS object-oriented knowledge: http://www.iteye.com/topic/434462
// 1th syntax function Circle (r) { this . R = R; } circle.pi = 3.14159 ; Circle.prototype.area = function () { ret Urn Circle.pi * this . R * this .R; var C = new Circle (1.0 ); Alert (C.area ());
// 2nd syntax var Circle = function () { var ob j = new Object (); Obj. PI = 3.14159 ; Obj.area = function (r) { return this . PI * r * R; return obj; var C = new Circle (); Alert (C.area ( 1.0 ));
// 3rd syntax var Circle = new Object (); Circle.pi = 3.14159 ; Circle.area = function (r) { return this . PI * r * R; } alert (Circle.area ( 1.0 ));
// 4th syntax var circle={ " pi : 3.14159 , area " :function (R) { return
this
. PI * r * R; } }; Alert (Circle.area ( 1.0 ));
// The 5th kind of notation var New Function ("this. PI = 3.14159;this.area = function (r) {return r*r*this. PI;} " ); Alert ((new Circle ()). Area (1.0));
Especially the last two kinds, often see.
JS Object-oriented