最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

javascript下拉框显示当前日期_时间日期

来源:动视网 责编:小采 时间:2020-11-27 20:38:20
文档

javascript下拉框显示当前日期_时间日期

javascript下拉框显示当前日期_时间日期:需要增加的地方: 代码如下:2010 2011 2012 2013 测试代码: 代码如下: * 您消费的时间 * 您消费的时间 2007 2008 2009 2010 2011 2012 2013 年 01 02 03 04 05 06 07 08 09 10 11 12 月 01 0
推荐度:
导读javascript下拉框显示当前日期_时间日期:需要增加的地方: 代码如下:2010 2011 2012 2013 测试代码: 代码如下: * 您消费的时间 * 您消费的时间 2007 2008 2009 2010 2011 2012 2013 年 01 02 03 04 05 06 07 08 09 10 11 12 月 01 0


需要增加的地方:
代码如下:





测试代码:
代码如下:





* 您消费的时间












* 您消费的时间












var today=new Date()//定义一个时间对象
var yy=today.getYear()
var mm=today.getMonth()+1
var dd=today.getDate()
var h=today.getHours()//定义小时
var m=today.getMinutes()//定义分钟
document.getElementById("years").options(yy-2007).selected=1
document.getElementById("months").options(mm-1).selected=1
document.getElementById("days").options(dd-1).selected=1
document.getElementById("hours").options(h).selected=1
document.getElementById("mins").options(m).selected=1




第二种方法:不需要事先写好年份,可扩展性比较好

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
第三种方法:不能用,但编程思路还可以,如果正式使用建议用第二种方法
代码如下:


New Document



function setDay(obj){
obj = obj.form;
var years=parseInt(obj.years.options[obj.years.selectedIndex].value);
var months=parseInt(obj.months.options[obj.months.selectedIndex].value);
if(obj.years.selectedIndex==0 || obj.months.selectedIndex==0)return;
var lastday = monthday(years,months);
var itemnum = obj.days.length;
if (lastday - 1 < obj.days.selectedIndex)
{
obj.days.selectedIndex = lastday - 1;
}
obj.days.length = lastday;
for(cnt = itemnum + 1;cnt <= lastday;cnt++)
{
obj.days.options[cnt - 1].text = cnt;
}
}
function monthday(years,months)
{
var lastday = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if (((years % 4 == 0) && (years % 100 != 0)) || (years % 400 == 0))
{
lastday[1] = 29;
}
return lastday[months - 1];
}
function forto(ff,to)
{
document.write('');
for(var ii=ff; ii<=to; ii++)
document.write('');
}
function a()
{
alert(document.all("years").value+"年"+document.all("months").value+"月"+document.all("days").value+"日") ;
}




文档

javascript下拉框显示当前日期_时间日期

javascript下拉框显示当前日期_时间日期:需要增加的地方: 代码如下:2010 2011 2012 2013 测试代码: 代码如下: * 您消费的时间 * 您消费的时间 2007 2008 2009 2010 2011 2012 2013 年 01 02 03 04 05 06 07 08 09 10 11 12 月 01 0
推荐度:
标签: 日期 js 下拉列表
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top