看代码。
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>如何实现一个日期下拉菜单</title>
<script type="text/javascript">
function DateSelector(selYear, selMonth)
{
this.selYear = selYear;
this.selMonth = selMonth;
this.InitYearSelect();
this.InitMonthSelect();
var dt = new Date();
this.selMonth.selectedIndex=dt.getMonth();
}
// 增加一个最大年份的属性
DateSelector.prototype.MinYear = 2010;// 增加一个最大年份的属性
DateSelector.prototype.MaxYear = (new Date()).getFullYear();// 初始化年份
DateSelector.prototype.InitYearSelect = function()
{
// 循环添加OPION元素到年份select对象中
for(var i = this.MaxYear; i >= this.MinYear; i--)
{
// 新建一个OPTION对象
var op = window.document.createElement("OPTION");
// 设置OPTION对象的值
op.value = i;
// 设置OPTION对象的内容
op.innerHTML = i;
// 添加到年份select对象
this.selYear.appendChild(op);
}
}
// 初始化月份
DateSelector.prototype.InitMonthSelect = function()
{
// 循环添加OPION元素到月份select对象中
for(var i = 1; i < 13; i++)
{
// 新建一个OPTION对象
var op = window.document.createElement("OPTION");
// 设置OPTION对象的值
op.value = i;
// 设置OPTION对象的内容
op.innerHTML = i;
// 添加到月份select对象
this.selMonth.appendChild(op);
}
}
</script>
</head>
<body>
<select id="selYear"></select>
<select id="selMonth"></select>
<script type="text/javascript">
var selYear = window.document.getElementById("selYear");
var selMonth = window.document.getElementById("selMonth");
// 新建一个DateSelector类的实例,将select对象传进去
new DateSelector(selYear, selMonth);
</script>
</body>
</html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>如何实现一个日期下拉菜单</title>
<script type="text/javascript">
function DateSelector(selYear, selMonth)
{
this.selYear = selYear;
this.selMonth = selMonth;
this.InitYearSelect();
this.InitMonthSelect();
var dt = new Date();
this.selMonth.selectedIndex=dt.getMonth();
}
// 增加一个最大年份的属性
DateSelector.prototype.MinYear = 2010;// 增加一个最大年份的属性
DateSelector.prototype.MaxYear = (new Date()).getFullYear();// 初始化年份
DateSelector.prototype.InitYearSelect = function()
{
// 循环添加OPION元素到年份select对象中
for(var i = this.MaxYear; i >= this.MinYear; i--)
{
// 新建一个OPTION对象
var op = window.document.createElement("OPTION");
// 设置OPTION对象的值
op.value = i;
// 设置OPTION对象的内容
op.innerHTML = i;
// 添加到年份select对象
this.selYear.appendChild(op);
}
}
// 初始化月份
DateSelector.prototype.InitMonthSelect = function()
{
// 循环添加OPION元素到月份select对象中
for(var i = 1; i < 13; i++)
{
// 新建一个OPTION对象
var op = window.document.createElement("OPTION");
// 设置OPTION对象的值
op.value = i;
// 设置OPTION对象的内容
op.innerHTML = i;
// 添加到月份select对象
this.selMonth.appendChild(op);
}
}
</script>
</head>
<body>
<select id="selYear"></select>
<select id="selMonth"></select>
<script type="text/javascript">
var selYear = window.document.getElementById("selYear");
var selMonth = window.document.getElementById("selMonth");
// 新建一个DateSelector类的实例,将select对象传进去
new DateSelector(selYear, selMonth);
</script>
</body>
</html>
解决方案 »
- php怎样实现当前位置功能?
- 大家帮忙看看为什么我把代码放到服务器就不能上传图片??
- 安装PHP的问题
- php出错后,继续执行下去,就像asp的 on error resume一样的功能有没有?
- PHP的域名查询类(不要小偷程序!谢谢!)
- 表news:id,title,link link表示引用id,比如link为2,表示当前记录指向id为2的记录,这样怎么select真实的数据呢?
- 用来匹配多层嵌套的正则在php中如何实现?
- 请问如何使页面只刷新一次?急!急!
- php和perl哪个更好?
- php的二级菜单联动问题
- 有啥方法及软件可以编辑JS
- 今天让我感动的一个CSDN的外包,希望大家都今天帮忙(倡议)
http://www.comsenz.com/downloads/install/supesite