This article mainly introduces the control of using JavaScript to implement effective time, and displays the time sample code that will expire. Need friends can come to the reference, I hope to help you.
JavaScript implementation of a set time validity, the sense of the implementation of their own jquery code is too concise, this is a colleague to write a section of JS code, their own research to learn a bit code as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/> <title> Untitled document </title> <style type=" Text/css "> #lastdate {color: #FF9900; Font-style:normal;} </style> </head> <body> <div class= "f-c" > <select id= "Date_sel" name= "period" class= "Buyconqc select150" > &NB Sp <option value= "0" > One day </option> &NB Sp <option value= "1" > Two days </option> &NB Sp <option value= "2" > Three days </option> &NB Sp <option value= "3" > Four days </option> ;/select> <span class= "postaction" > in <em id= "Lastdate" >2012-9-28</ After em> , will expire </span> </div> <script type= "Text/javascript" > document.getElementById (' Date_sel '). onchange = function () { var time = new Date (); var pre_year = Time.getfullyear (); var pre_month = Time.getmonth (); var pre_day = Time.getdate (); var sel_day = parseint (document.getElementById (' Date_sel '). Value); switch (sel_day) { Case 0:pre_day +=1;break; case 1:pre_day +=2;break; case 2:pre_day +=3;break; case 3:pre_day +=4;break; Default:pre_day +=1;break; } var endtime = new Date (pre_year, Pre_month, Pre_day); document.getElementById (' lastdate '). InnerHTML = Endtime.getfullyear () + "-" + (Endtime.getmonth () +1) + "-" +endtime.getdate (); }; </script> </body> </html>