欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js+html制作簡(jiǎn)單日歷的方法

 更新時(shí)間:2017年06月27日 17:09:45   作者:永朋  
這篇文章主要為大家詳細(xì)介紹了js html制作簡(jiǎn)單日歷的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

新手一枚,不會(huì)寫(xiě)什么高大上的博文,一些平時(shí)做的小練習(xí),獻(xiàn)丑

代碼:

<!doctype html>
<html>

 <head>
 <meta charset="utf-8">
 <title>無(wú)標(biāo)題文檔</title>
 <style>
  * {margin: 0;padding: 0}
  #calendar {width: 210px;margin: 100px auto;overflow: hidden;border: 1px solid #000;padding: 20px;position: relative}
  #calendar h4 {text-align: center;margin-bottom: 10px}
  #calendar .a1 {position: absolute;top: 20px;left: 20px;}
  #calendar .a2 {position: absolute;top: 20px;right: 20px;}
  #calendar .week {height: 30px;line-height: 20px;border-bottom: 1px solid #000;margin-bottom: 10px}
  #calendar .week li {float: left;width: 30px;height: 30px;text-align: center;list-style: none;}
  #calendar .dateList {overflow: hidden;clear: both}
  #calendar .dateList li {float: left;width: 30px;height: 30px;text-align: center;line-height: 30px;list-style: none;}
  #calendar .dateList .ccc {color: #ccc;}
  #calendar .dateList .red {background: #F90;color: #fff;}
  #calendar .dateList .sun {color: #f00;}
 </style>
 <script src="js/jquery-1.11.3.min.js"></script>
 <script>
  $(function() {

  //必要的數(shù)據(jù)
  //今天的年 月 日 ;本月的總天數(shù);本月第一天是周幾???
  var iNow=0;
  
  function run(n) {

   var oDate = new Date(); //定義時(shí)間
   oDate.setMonth(oDate.getMonth()+n);//設(shè)置月份
   var year = oDate.getFullYear(); //年
   var month = oDate.getMonth(); //月
   var today = oDate.getDate(); //日

   //計(jì)算本月有多少天
   var allDay = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];

   //判斷閏年
   if(month == 1) {
   if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
    allDay = 29;
   }
   }

   //判斷本月第一天是星期幾
   oDate.setDate(1); //時(shí)間調(diào)整到本月第一天
   var week = oDate.getDay(); //讀取本月第一天是星期幾

   //console.log(week);
   $(".dateList").empty();//每次清空
   //插入空白

   for(var i = 0; i < week; i++) {
   $(".dateList").append("<li></li>");
   }

   //日期插入到dateList
   for(var i = 1; i <= allDay; i++) {
   $(".dateList").append("<li>" + i + "</li>")
   }
   //標(biāo)記顏色=====================
   $(".dateList li").each(function(i, elm){
   //console.log(index,elm);
   var val = $(this).text();
   //console.log(val);
   if (n==0) {
    if(val<today){
    $(this).addClass('ccc')
   }else if(val==today){
    $(this).addClass('red')
   }else if(i%7==0 || i%7==6 ){
    $(this).addClass('sun')
   }
   }else if(n<0){
    $(this).addClass('ccc')
   }else if(i%7==0 || i%7==6 ){
    $(this).addClass('sun')
   }
   });

   //定義標(biāo)題日期
   $("#calendar h4").text(year + "年" + (month + 1) + "月");
  };
  run(0);
  
  $(".a1").click(function(){
   iNow--;
   run(iNow);
  });
  
  $(".a2").click(function(){
   iNow++;
   run(iNow);
  })
  });
 </script>
 </head>

 <body>
 <div id="calendar">
  <h4>2013年10月</h4>
  <a href="##" rel="external nofollow" rel="external nofollow" class="a1">上月</a>
  <a href="##" rel="external nofollow" rel="external nofollow" class="a2">下月</a>
  <ul class="week">
  <li>日</li>
  <li>一</li>
  <li>二</li>
  <li>三</li>
  <li>四</li>
  <li>五</li>
  <li>六</li>

  </ul>
  <ul class="dateList"></ul>
 </div>

 </body>

</html>

更多精彩內(nèi)容請(qǐng)點(diǎn)擊專(zhuān)題《javascript日歷插件使用方法匯總》進(jìn)行學(xué)習(xí)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • javascript實(shí)現(xiàn)表單驗(yàn)證

    javascript實(shí)現(xiàn)表單驗(yàn)證

    這篇文章主要介紹了javascript實(shí)現(xiàn)表單驗(yàn)證的相關(guān)資料,以一個(gè)完整的實(shí)例對(duì)javascript實(shí)現(xiàn)表單驗(yàn)證的方法進(jìn)行分析,感興趣的小伙伴們可以參考一下
    2016-01-01
  • ECMAscript新特性對(duì)象介紹

    ECMAscript新特性對(duì)象介紹

    這篇文章主要介紹了ECMAscript新特性對(duì)象,對(duì)象(object)是JavaScript最重要的數(shù)據(jù)結(jié)構(gòu)。ECMAScript 2015對(duì)它進(jìn)行了重大升級(jí),下面我們來(lái)看一下它的改變

    2021-12-12
  • js 單擊式的下拉菜單效果實(shí)例

    js 單擊式的下拉菜單效果實(shí)例

    這篇文章介紹了js 單擊式的下拉菜單效果實(shí)例,有需要的朋友可以參考一下
    2013-08-08
  • 修復(fù)IE9&safari 的sort方法

    修復(fù)IE9&safari 的sort方法

    解決方案其實(shí)就是冒泡排序的一個(gè)包裝,本補(bǔ)丁不修復(fù)各瀏覽的排序算法不一致的問(wèn)題
    2011-10-10
  • 淺談Webpack是如何打包CommonJS的

    淺談Webpack是如何打包CommonJS的

    CommonJS是Node中的一種模塊化規(guī)范,本文主要介紹了Webpack是如何打包CJS的,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • js獲取數(shù)組對(duì)象中的全部key和value值

    js獲取數(shù)組對(duì)象中的全部key和value值

    本文主要介紹了js獲取數(shù)組對(duì)象中的全部key和value值,主要使用JavaScript的?map()?函數(shù)和?values()?迭代器來(lái)實(shí)現(xiàn)取出數(shù)組對(duì)象的所有key值和value值,感興趣的可以了解下
    2024-01-01
  • 微信小程序?qū)崿F(xiàn)購(gòu)物車(chē)功能

    微信小程序?qū)崿F(xiàn)購(gòu)物車(chē)功能

    這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)購(gòu)物車(chē)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • JavaScript數(shù)組reduce常見(jiàn)實(shí)例方法

    JavaScript數(shù)組reduce常見(jiàn)實(shí)例方法

    reduce方法在數(shù)組的每個(gè)元素上執(zhí)行用戶(hù)提供的回調(diào)函數(shù),即"reducer",它傳入對(duì)前一個(gè)元素進(jìn)行計(jì)算的返回值,結(jié)果是單個(gè)值,它是在數(shù)組的所有元素上運(yùn)行reducer的結(jié)果,下面這篇文章主要給大家介紹了關(guān)于JavaScript數(shù)組reduce常見(jiàn)實(shí)例方法的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • js獲取當(dāng)前日期時(shí)間及其它操作匯總

    js獲取當(dāng)前日期時(shí)間及其它操作匯總

    Js獲取當(dāng)前日期時(shí)間及其它操作,還有一些自己常用的方法,很好用,也很全。這里推薦給大家,有需要的小伙伴可以參考下。
    2015-04-04
  • 一文詳解前端進(jìn)階之IntersectionObserver

    一文詳解前端進(jìn)階之IntersectionObserver

    這篇文章主要為大家介紹了前端進(jìn)階之IntersectionObserver示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04

最新評(píng)論