JavaScript to achieve effective time control

Source: Internet
Author: User
Tags getdate set time

  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>  
Related Article

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.