用jquery写的一个万年历(自写) - Web前端
作者:98wpeu发布时间:2026-06-18分类:网页前端技术浏览:2
导读:复制代码代码如下:<!Doctypehtml><HTMLxmlns=http://www.w3.org/1999/xhtml><head>...
复制代码 代码如下:
<!Doctypehtml><HTMLxmlns=http://www.w3.org/1999/xhtml>
<head>
<metaHTTP-eqUIv=Content-Type content="text/html;charset=utf-8">
<style>
.mAIn{
width:600px;
height:350px;
background:gray;
margin-left: auto;
margin-right: auto;
overflow:hidden;
-WEBkit-border-radius: 10px;
-moz-border-radius: 10px;
}
.title{
text-align:center;
}
.date{
float:left;
padding-left:31px;
}
.Date1{
float:left;
width:20px;
height:20px;
padding-top:10px;
padding-left:30px;
padding-right:30px;
}
.content{
margin-left:25px;
}
</style>
<script type="text/javascript" src="JQuery.min.JS"></script>
<script>
functiongettime(year,month,day){
y = year
m = month
d = day
var myDate = new date(year,month-1,day);
return myDate;
}
function days_in_month(year, month) {
y = year;
m = month;
return 32 - new Date(y, m - 1, 32).getDate();
}
function view(year,month){
var w = getTime(year,month,1).getDay()-1;
var num = days_in_month(year,month);
var index = 1;
//console.log(w);
var data = new Array();
for(var d = 0; d < num+w; d++){
if(d<w){
data[d] = '';
}else{
data[d] = index;
index++;
}
}
$("#content").html('');
for(var k =0;k < data.length;k++){
if(k%7==0){
$("#content").append("<div id='t"+k+"' class='date1'>"+data[k]+"</div><br>");
}else{
$("#content").APPend("<div id='t"+k+"' class='date1'>"+data[k]+"</div>");
}
}
$("#content > div").mouSEOver(function(){
if($(this).text()!=''){
$(this).CSS('background','red');
}
});
$("#content > div").mouseout(function(){
if($(this).text()!=''){
$(this).css('background','gray');
}
});
}
$(document).ready(function (){
for(var t = 1970; t < 2999; t++){
$("#yearsel").append("<option value ='"+t+"'>"+t+"</option>");
}
for(var y = 1; y < 13;y++){
$("#monthsel").Append("<option value ='"+y+"'>"+y+"</option>");
}
var year = new Date().getFullYear();
var month = new Date().getMonth()+1;
var day = new Date().getDate();
var w = getTime(year,month,1).getDay()-1;
var num = day + w -1;
$("#yearsel").change(function(){
year = $("#yearsel option:selected").text();
month = $("#monthsel option:selected").text();
vIEw(year,month);
});
$("#monthsel").change(function(){
year = $("#yearsel option:selected").text();
month = $("#monthsel option:selected").text();
view(year,month);
});
var oDate = ['星期一','星期二','星期三','星期四','星期五','星期六','星期日',];
for(var i = 0;i < 7;i++){
$("#title").append("<div class='date'><b>"+oDate[i]+"</b></div>");
}
$("#yearsel option[value='"+year+"']").attr("selected", true);
view(year,month);
//标记当前日期
$("#t"+num).css('background','yellow');
});
</script>
</head>
<body>
<div id="main" class="main">
<center><h3>万年历</h3></center>
<select id="yearsel">
</select>年
<select id="monthsel">
</select>月<br><br>
<div id="title" class="title">
</div>
<div id="content" class="content">
</div>
</div>
</body>
</html>
<!Doctypehtml><HTMLxmlns=http://www.w3.org/1999/xhtml>
<head>
<metaHTTP-eqUIv=Content-Type content="text/html;charset=utf-8">
<style>
.mAIn{
width:600px;
height:350px;
background:gray;
margin-left: auto;
margin-right: auto;
overflow:hidden;
-WEBkit-border-radius: 10px;
-moz-border-radius: 10px;
}
.title{
text-align:center;
}
.date{
float:left;
padding-left:31px;
}
.Date1{
float:left;
width:20px;
height:20px;
padding-top:10px;
padding-left:30px;
padding-right:30px;
}
.content{
margin-left:25px;
}
</style>
<script type="text/javascript" src="JQuery.min.JS"></script>
<script>
functiongettime(year,month,day){
y = year
m = month
d = day
var myDate = new date(year,month-1,day);
return myDate;
}
function days_in_month(year, month) {
y = year;
m = month;
return 32 - new Date(y, m - 1, 32).getDate();
}
function view(year,month){
var w = getTime(year,month,1).getDay()-1;
var num = days_in_month(year,month);
var index = 1;
//console.log(w);
var data = new Array();
for(var d = 0; d < num+w; d++){
if(d<w){
data[d] = '';
}else{
data[d] = index;
index++;
}
}
$("#content").html('');
for(var k =0;k < data.length;k++){
if(k%7==0){
$("#content").append("<div id='t"+k+"' class='date1'>"+data[k]+"</div><br>");
}else{
$("#content").APPend("<div id='t"+k+"' class='date1'>"+data[k]+"</div>");
}
}
$("#content > div").mouSEOver(function(){
if($(this).text()!=''){
$(this).CSS('background','red');
}
});
$("#content > div").mouseout(function(){
if($(this).text()!=''){
$(this).css('background','gray');
}
});
}
$(document).ready(function (){
for(var t = 1970; t < 2999; t++){
$("#yearsel").append("<option value ='"+t+"'>"+t+"</option>");
}
for(var y = 1; y < 13;y++){
$("#monthsel").Append("<option value ='"+y+"'>"+y+"</option>");
}
var year = new Date().getFullYear();
var month = new Date().getMonth()+1;
var day = new Date().getDate();
var w = getTime(year,month,1).getDay()-1;
var num = day + w -1;
$("#yearsel").change(function(){
year = $("#yearsel option:selected").text();
month = $("#monthsel option:selected").text();
vIEw(year,month);
});
$("#monthsel").change(function(){
year = $("#yearsel option:selected").text();
month = $("#monthsel option:selected").text();
view(year,month);
});
var oDate = ['星期一','星期二','星期三','星期四','星期五','星期六','星期日',];
for(var i = 0;i < 7;i++){
$("#title").append("<div class='date'><b>"+oDate[i]+"</b></div>");
}
$("#yearsel option[value='"+year+"']").attr("selected", true);
view(year,month);
//标记当前日期
$("#t"+num).css('background','yellow');
});
</script>
</head>
<body>
<div id="main" class="main">
<center><h3>万年历</h3></center>
<select id="yearsel">
</select>年
<select id="monthsel">
</select>月<br><br>
<div id="title" class="title">
</div>
<div id="content" class="content">
</div>
</div>
</body>
</html>
- 上一篇:jquery提交form表单时禁止重复提交的方法 - Web前端
- 下一篇:已经是最后一篇了
相关推荐
- jquery提交form表单时禁止重复提交的方法 - Web前端
- jquery操作select详解(取值,设置选中) - Web前端
- jquery 字符串切割函数substring的用法说明 - Web前端
- Jquery Uploadify上传带进度条的简单实例 - Web前端
- 文本框文本自动补全效果示例分享 - Web前端
- jQuery插件开发的两种方法及$.fn.extend的详解 - Web前端
- 为指定的元素添加遮罩层的示例代码 - Web前端
- jquery事件重复绑定的快速解决方法 - Web前端
- Jquery 获取对象的几种方式介绍 - Web前端
- jquery中event对象属性与方法小结 - Web前端
- 网页前端技术排行
-
- 1【第六章】Foundation之按钮和下拉功能 - Web前端
- 2在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 3jQuery编写widget的一些技巧分享 - Web前端
- 4基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 5jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 6分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 7JS网页制作实例:标签云 - Web前端
- 8[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 9分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


