js執行個體8日期的選擇

來源:互聯網
上載者:User

標籤:for   date   str   cli   i++   執行個體   ext   fill   type   

 

<body>

<select id="nian" onclick="biantian()"></select>年
<select id="yue" onclick="biantian()"></select>月
<select id="tian"></select>日

<script type="text/javascript">
FillNian();
FillYue();
FillTian();
function FillNian()
{
var b = new Date(); //擷取目前時間
var nian = parseInt(b.getFullYear());

var str = "";

for(var i=nian-5;i<nian+6;i++)
{
str = str+"<option value=‘"+i+"‘>"+i+"</option>";
}

document.getElementById("nian").innerHTML = str;

}

function FillYue()
{
var str = "";
for(var i=1;i<13;i++)
{
str = str+"<option value=‘"+i+"‘>"+i+"</option>";
}
document.getElementById("yue").innerHTML = str;
}

function FillTian()
{
var yue = document.getElementById("yue").value;
var nian = document.getElementById("nian").value;
var ts = 31;

if(yue==4 || yue==6 || yue==9 || yue==11)
{
ts=30;
}

if(yue==2)
{
if((nian%4==0 && nian%100 != 0) || nian%400==0)
{
ts = 29;
}
else
{
ts = 28;
}
}

var str = "";
for(var i=1;i<ts+1;i++)
{
str = str+"<option value=‘"+i+"‘>"+i+"</option>";
}
document.getElementById("tian").innerHTML = str;



}


function biantian()
{
FillTian();
}
</script>
</body>

js執行個體8日期的選擇

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.