• Javascript实现万年历(日历表)


    在这里插入图片描述

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8">
    		<title></title>
    		<style type="text/css">
    			.main {
    				width: 800px;
    				margin: 0 auto;
    
    			}
    
    			.top {
    				width: 800px;
    				margin: 0 auto;
    			}
    
    			#nian {
    				width: 100px;
    				height: 30px;
    				display: block;
    			}
    
    			#yue {
    				width: 100px;
    				height: 30px;
    				display: block;
    			}
    
    			.float {
    
    				display: block;
    				width: 50px;
    			}
    
    			.center {
    
    				margin: 0 auto;
    				width: 800px;
    			}
    
    			#tab tr {
    				height: 150px;
    
    			}
    
    			#tab tr td,
    			th {
    				width: 150px;
    			}
    		</style>
    	</head>
    	<body>
    		<div class="main">
    			<div class="top">
    				<select id="nian" class="float" onchange="huan()">
    
    				</select>
    				<span class="float"></span>
    				<select id="yue" class="float" onchange="huan()">
    
    				</select>
    				<span class="float"></span>
    			</div>
    
    
    		</div>
    		<div class="center">
    			<table id="tab" border="" cellspacing="" cellpadding="">
    				<tr>
    					<th>周日</th>
    					<th>周一</th>
    					<th>周二</th>
    					<th>周三</th>
    					<th>周四</th>
    					<th>周五</th>
    					<th>周六</th>
    				</tr>
    			</table>
    		</div>
    		<script type="text/javascript">
    			
    			var tab = document.getElementById("tab");
    			window.onload = function() {
    				var nian = document.getElementById("nian");
    				var yue = document.getElementById("yue");
    				for (var i = 2019; i >= 1970; i--) {
    					var sel = document.createElement("option");
    					sel.value = i;
    					sel.innerText = i;
    					nian.appendChild(sel);
    				}
    				for (var i = 1; i <= 12; i++) {
    					var sel = document.createElement("option");
    					sel.value = i;
    					sel.innerText = i;
    					yue.appendChild(sel);
    				}
    				huan();
    			}
    
    			 function huan() {
    				var week = 0;//周几
    				var day = 1;//从第一天开始
    				var days = 30;//这个月一共有几天
    				// try{
    				// 	var ziji=document.getElementsByTagName("td")[0];
    				// 	ziji.parentElement.parentElement.removeChild(ziji.parentElement);
    									
    				// }catch(e){
    				// 	//TODO handle the exception
    				// }
    					try{
    						//添加一个add1的类,方便删除
    						var dataa=document.getElementsByClassName("add1");
    						for(var i=0;i<dataa.length;){
    							dataa[0].remove();
    						}
    					}catch(e){
    						//TODO handle the exception
    						
    					}
    			
    				var nian = document.getElementById("nian").value;
    				var yue = document.getElementById("yue").value;
    				var date = new Date(nian + "-" + yue + "-1");
    				//计算这个月有多少天
    				var data = new Date(nian,yue,0);
    				 days=data.getDate();
    				 // alert(days)
    
    				var newtr = document.createElement("tr");
    				newtr.classList.add("add1");
    				for (var i = 0; i < date.getDay(); i++) {
    					if (week == 7) {
    						week = 0;
    					}
    					var newtd = document.createElement("td");
    					
    					newtr.appendChild(newtd);
    					week++;
    
    				}
    				if (week <= 6) {
    					for (; week <= 6; week++, day++) {
    						var newtd = document.createElement("td");
    						newtd.innerText = day;
    						newtd.value = day;
    						newtr.appendChild(newtd);
    
    
    					}
    				}
    				tab.appendChild(newtr);
    				week = 0;
    				newtr = document.createElement("tr");
    					newtr.classList.add("add1");
    				for (; day <= days; day++, week++) {
    					if (week == 7) {
    						week = 0;
    						tab.appendChild(newtr);
    						newtr = document.createElement("tr");
    							newtr.classList.add("add1");
    					}
    					var newtd = document.createElement("td");
    					newtd.innerText = day;
    					newtd.value = day;
    					newtr.appendChild(newtd);
    				}
    				tab.appendChild(newtr);
    			}
    		</script>
    	</body>
    </html>
    
    
  • 相关阅读:
    新的开始 和一些总结
    常用物流快递单号查询API接口对接net源码示例_快递鸟
    从SpringBoot到SpringCloudAlibaba简明教程(一):初识SpringBoot及其基础项目构建
    Debug > python list.sort()食用方法
    Debug > python统计列表中元素个数
    Debug > python中的True False 0 1
    java获取本机外网ipV4
    aop统一处理修改请求参数
    [算法] 国家地区数组按照中文首字母排序
    js转换ASCII码
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076451.html
Copyright © 2020-2023  润新知