JavaScript实现的一个设置时间有效期的,自己用jQuery实现的感觉代码太不简练,这个是同事写的一段js代码,自己研究学习了一下
复制代码 代码如下:
<!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>无标题文档</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">
                           <option value="0">一天内</option>
                           <option value="1">两天内</option>
                           <option value="2">三天内</option>
                           <option value="3">四天内</option>

          </select>
        <span class="postAction">在  <em id="lastdate">2012-9-28</em>  后,将过期</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>

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!