9月23日JavaScript作业----日期时间选择
作业二:日期时间选择
<div style="width:600px; height:100px;">
<select id="year"></select>年
<select id="month" onchange="FillDay()"></select>月
<select id="day"></select>日
</div>
</body>
<script type="text/javascript">
FillYear();
FillMonth();
FillDay();
function FillYear()
{
var sj = new Date();//现在的日期时间
var nian = sj.getFullYear();//获取年份
var s = "";
for(var i=nian-5;i<nian+6;i++)//上下都是5年,i里面存的是年
{
if(i==nian)//如果i等于当前的年,也就是2016年。
{
s +="<option selected='selected'>"+i+"</option>";//下拉列表中默认出现的年份
}
else
{
s +="<option>"+i+"</option>";//普通的年份
}
} document.getElementById("year").innerHTML = s;//把这个字符串给年份的下拉
}
function FillMonth()
{
var sj = new Date();//在这个位置调用
var yue = sj.getMonth()+1;
var s = "";
for(var i=1;i<13;i++)
{
if(i==yue)
{
s +="<option selected='selected'>"+i+"</option>";
}
else
{
s +="<option>"+i+"</option>";
}
}
document.getElementById("month").innerHTML=s;
}
function FillDay()
{
var sj = new Date();
var tian = sj.getDate();
var yue = document.getElementById("month").value; 取月份求天数
var n = 31;
if(yue==4 || yue==6 ||yue==9 ||yue==11)
{
n = 30;
}
else if(yue==2)
{
n=28;
}
var s = ""; 用循环添加
for(var i=1;i<n+1;i++)
{
if(i==tian)
{
s +="<option selected='selected'>"+i+"</option>";
}
else
{
s +="<option>"+i+"</option>";
}
}
document.getElementById("day").innerHTML = s;
}
9月23日JavaScript作业----日期时间选择的更多相关文章
- 9月23日JavaScript作业----子菜单下拉
例题一.子菜单下拉 <style type="text/css"> *{ margin:0px auto; padding:0px} #menu{ width:700p ...
- 9月23日JavaScript作业----用DIV做下拉列表
例题二.用div做下拉列表 <title>无标题文档</title> <style type="text/css"> *{ margin:0px ...
- 9月23日JavaScript作业----两个列表之间移动数据
作业一:两个列表之间数据从一个列表移动到另一个列表 <div style="width:600px; height:500px; margin-top:20px"> & ...
- 5月23日 JavaScript
一.JavaScript简介 1.JavaScript是什么: 它是个脚本语言,需要有宿主文件,它的宿主文件是HTML文件. 2.它的用法: 在HTML中位置有三块: (1)head里面 (2)bod ...
- 5月23日 JavaScript练习:累加求和
第一种方法: 第二种方法:
- Week16(12月23日):复习
Part I:提问 =========================== 1.声明强类型视图时,使用关键字( ) A.ViewBag B.model C.Type D.Tit ...
- 2016年12月23日 星期五 --出埃及记 Exodus 21:18
2016年12月23日 星期五 --出埃及记 Exodus 21:18 "If men quarrel and one hits the other with a stone or with ...
- [分享] 从定制Win7母盘到封装详细教程 By BILL ( 10月23日补充说明 )
[分享] 从定制Win7母盘到封装详细教程 By BILL ( 10月23日补充说明 ) billcheung 发表于 2011-10-23 00:07:49 https://www.itsk.com ...
- 11月23日《奥威Power-BI报表集成到其他系统》腾讯课堂开课啦
听说明天全国各地区都要冷到爆了,要是天气冷到可以放假就好了.想象一下大冷天的一定要在被窝里度过才对嘛,索性明天晚上来个相约吧,相约在被窝里看奥威Power-BI公开课如何? 上周奥威公开 ...
随机推荐
- python环境搭建-Linux系统下python2.6.6升级python3.5.2步骤
[root@template ~]# python -v # /usr/lib64/python2.6/encodings/utf_8.pyc matches /usr/lib64/python2.6 ...
- 模拟发送http请求
1.httpie 2.postman:Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件. 3.fiddler
- fio 2种画图方法 fio_generate_plots 和 gfio
fio 安装fio apt-get install fio 可以把fio的输出数据自动画图的插件gnuplot apt-get install gnuplot 1.输出bw,lat和iops数据并画图 ...
- iOS开发小技巧--TableView Group样式中控制每个section之间的距离
一.TableView的Group样式中,默认的每个section都有sectionHeader和sectionFooter,只要调整这两个的大小就可以实现section之前的间距扩大或缩小 二.项目 ...
- 【BZOJ 1043】【HNOI 2008】下落的圆盘 判断圆相交+线段覆盖
计算几何真的好暴力啊. #include<cmath> #include<cstdio> #include<cstring> #include<algorit ...
- 51nod 1076强连通
Tarjan算法来解这题.无向图可以转化为有向图来解决. #include<map> #include<queue> #include<stack> #includ ...
- Jquery-下拉列表设置默认选择
$('#select option:eq(2)').attr('selected','selected');
- ActiveMQ;RabbitMQ;ZeroMQ
中间件类型: Embedded middleware: As the name suggests, this typeof middleware handles embedded applicatio ...
- 【BZOJ-1468】Tree 树分治
1468: Tree Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1025 Solved: 534[Submit][Status][Discuss] ...
- 【BZOJ-4524】伪光滑数 堆 + 贪心 (暴力) [可持久化可并堆 + DP]
4524: [Cqoi2016]伪光滑数 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 183 Solved: 82[Submit][Status] ...