javascript html实现网页版日历代码


Posted in Javascript onMarch 08, 2016

本文实例为大家分享了网页版日历代码,供大家参考,具体内容如下

效果图:

javascript html实现网页版日历代码

实现代码:

<html>
 <head>
  <link rel="stylesheet" type="text/css" href="Skin.css">
  <style>
  <!--
  table{ text-align: center }
  -->
  </style>
 </head>
 
 <body>
  <div align="center">
   <script language="javascript">
   var my = new Date();
   
   function showc() {
    var k=1;
    var j=1;
    var today;
    var tomonth;
    var theday=1;//日期
    var max;
    var temp;
    var tempday;//这个月第一天的星期
    document.write ("<b>" + my.getFullYear() + "-" + (my.getMonth()+1) + "</b>");
    document.write ("<table border='1' width='273' height='158'>");
    document.write ("<tr>");
    document.write ("<td height='23' width='39'><font color='red'>Sun</font></td>");
    document.write ("<td height='23' width='39'>Mon</td>");
    document.write ("<td height='23' width='39'>Tue</td>");
    document.write ("<td height='23' width='39'>Wed</td>");
    document.write ("<td height='23' width='39'>Thu</td>");
    document.write ("<td height='23' width='39'>Fri</td>");
    document.write ("<td height='23' width='39'>Sat</td>");
    document.write ("</tr>");
    temp=my.getDate();
    my.setDate(1);
    //document.write (my.getDate());
    tempday=my.getDay();//返回第一天是星期几
    my.setDate(temp);
    today=my.getDay();//返回现在星期几
   
    switch ((my.getMonth()+1)) {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    max=31;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    max=30;
    break;
    default:
    max=29;//这里没有考虑闰月!!
    //document.write (max);
    }
    for(k=0;k<6;k++) {
    document.write ("<tr>");
    for(j=0;j<=6;j++) {
    document.write ("<td height='23' width='39'>");
    if(j>=(tempday)) {
    tempday=0;//设置为最小,相当于取消判断条件
    if(theday<=max) {
     document.write ("<a title=" + my.getFullYear() + "-" + (my.getMonth()+1) + "-" +theday + " target='_blank' href=detail.asp?date=" + theday + ">");
     if(theday==my.getDate())
     document.write ("<font color='green'>[" + theday + "]</font></a>");
     else if(j==0)
     document.write ("<font color='red'>" + theday + "</font></a>");
     else
     document.write (theday + "</a>");
     theday++;
    }
    }
    document.write ("</td>");
    }
    document.write ("</tr>");
    }
    document.write ("</table>");
   }
   
   showc();
  </script>
  </div>
 <body>
</html>

以上就是本文的全部内容,希望大家可以轻松实现网页版日历。

Javascript 相关文章推荐
理解Javascript_14_函数形式参数与arguments
Oct 20 Javascript
Javascript 中 null、NaN和undefined的区别总结
Apr 10 Javascript
探寻Javascript执行效率问题
Nov 12 Javascript
JS通过Cookie判断页面是否为首次打开
Feb 05 Javascript
基于JS实现textarea中获取动态剩余字数的方法
May 25 Javascript
VueJs单页应用实现微信网页授权及微信分享功能示例
Jul 26 Javascript
[js高手之路]设计模式系列课程-发布者,订阅者重构购物车的实例
Aug 29 Javascript
详解React中setState回调函数
Jun 14 Javascript
微信小程序仿RadioGroup改变样式的处理方案
Jul 13 Javascript
JS实现面向对象继承的5种方式分析
Jul 21 Javascript
vuejs实现折叠面板展开收缩动画效果
Sep 06 Javascript
使用react-virtualized实现图片动态高度长列表的问题
May 28 Javascript
一道关于JavaScript变量作用域的面试题
Mar 08 #Javascript
理解javascript函数式编程中的闭包(closure)
Mar 08 #Javascript
jQuery实现带水平滑杆的焦点图动画插件
Mar 08 #Javascript
javascript对象的创建和访问
Mar 08 #Javascript
js获取当前日期时间及其它日期操作汇总
Mar 08 #Javascript
使用JQuery实现智能表单验证功能
Mar 08 #Javascript
js表单处理中单选、多选、选择框值的获取及表单的序列化
Mar 08 #Javascript
You might like
探讨PHP JSON中文乱码的解决方法详解
2013/06/06 PHP
利用php下载xls文件(自己动手写的)
2014/04/18 PHP
一组PHP加密解密函数分享
2014/06/05 PHP
PHP实现一个多功能购物网站的案例
2017/09/13 PHP
PHP长连接实现与使用方法详解
2018/02/11 PHP
php 读写json文件及修改json的方法
2018/03/07 PHP
写得不错的jquery table鼠标经过变色代码
2013/09/27 Javascript
js日期相关函数总结分享
2013/10/15 Javascript
JS数组的赋值介绍
2014/03/10 Javascript
jQuery Raty 一款不错的星级评分插件
2016/08/24 Javascript
vue从使用到源码实现教程详解
2016/09/19 Javascript
jQuery基本筛选选择器实例代码
2017/02/06 Javascript
AngularJS入门教程二:在路由中传递参数的方法分析
2017/05/27 Javascript
AngularJS获取json数据的方法详解
2017/05/27 Javascript
详解react使用react-bootstrap当轮子造车
2017/08/15 Javascript
vue内置组件transition简单原理图文详解(小结)
2018/07/12 Javascript
基于vue-cli 路由 实现类似tab切换效果(vue 2.0)
2019/05/08 Javascript
微信小程序 如何获取网络状态
2019/07/26 Javascript
Nest.js 授权验证的方法示例
2021/02/22 Javascript
[16:43]Heroes19_剃刀(完美)
2014/10/31 DOTA
python中enumerate函数用法实例分析
2015/05/20 Python
Python协程的用法和例子详解
2017/09/09 Python
Python读取Json字典写入Excel表格的方法
2018/01/03 Python
wxPython实现窗口用图片做背景
2018/04/25 Python
对pandas将dataframe中某列按照条件赋值的实例讲解
2018/11/29 Python
详解django中Template语言
2020/02/22 Python
Python3读取和写入excel表格数据的示例代码
2020/06/09 Python
python如何利用Mitmproxy抓包
2020/10/10 Python
玩转CSS3色彩
2010/01/16 HTML / CSS
李维斯德国官方网上商店:Levi’s德国
2016/09/10 全球购物
C#面试问题
2016/07/29 面试题
男女朋友协议书
2014/04/23 职场文书
计算机毕业生求职信
2014/06/10 职场文书
物理学专业求职信
2014/07/04 职场文书
Java Shutdown Hook场景使用及源码分析
2021/06/15 Java/Android
python如何利用cv2.rectangle()绘制矩形框
2022/12/24 Python