var date1 = 怎样拆分为select二级列表联
2个回答
展开全部
<script type="text/javascript">
window.onload = function()
{
var now = new Date();
var currentYear = now.getFullYear();
var currentMonth = now.getMonth() + 1;
BindSelect(document.getElementById('year'), currentYear - 50, currentYear + 10, currentYear);
BindSelect(document.getElementById('month'), 1, 12, currentMonth);
}
function BindSelect(selectObj, startValue, endValue, selectedValue)
{
var i = 0;
for(var val = startValue; val <= endValue; val++)
{
selectObj.options.add(new Option(val , val));
if(val == selectedValue)selectObj.options[i].selected = true;
i++;
}
}
</script>
<select id="year"></select>年<select id="month"></select>月
window.onload = function()
{
var now = new Date();
var currentYear = now.getFullYear();
var currentMonth = now.getMonth() + 1;
BindSelect(document.getElementById('year'), currentYear - 50, currentYear + 10, currentYear);
BindSelect(document.getElementById('month'), 1, 12, currentMonth);
}
function BindSelect(selectObj, startValue, endValue, selectedValue)
{
var i = 0;
for(var val = startValue; val <= endValue; val++)
{
selectObj.options.add(new Option(val , val));
if(val == selectedValue)selectObj.options[i].selected = true;
i++;
}
}
</script>
<select id="year"></select>年<select id="month"></select>月
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询