人生倒计时
人生倒计时
出生年份: 出生月份:
<!DOCTYPE html> <html id="spLianghui"> <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>人生倒计时</title><script>function goDead() {var y = document.getElementById("txtYear").value;var m = document.getElementById("txtMonth").value;var cY = new Date().getFullYear();var cM = new Date().getMonth();document.getElementById("divL").innerHTML = "你的人生已经度过了" + ((((cY - y) / 70) * 100).toFixed(2) + "%");var endY = parseInt(y) + 70;var strHTML = "";for (var i = y; i <= endY; i++) {if (cY > i) {strHTML += "<tr style='background-color:red' ><td >" + i + "</td>";} else {strHTML += "<tr><td style='background-color:blue'>" + i + "</td>";}for (var j = 1; j <= 12; j++) {if (i == cY && j <= cM) {strHTML += "<td style='background-color:red'>" + j + "</td>";} else if (cY > i) {strHTML += "<td style='background-color:red'>" + j + "</td>";}else {strHTML += "<td style='background-color:blue'>" + j + "</td>";}}strHTML += "</tr>";}strHTML = "<table border=\"1\" width=\"100%\" ><tr><td>年份</td><td colspan='12'>月份</td></tr>" + strHTML + "</table>";document.getElementById("divHTML").innerHTML = strHTML;alert('计算完成...');}</script></head> <body><h1 style="text-align:center" >人生倒计时</h1>出生年份:<input id="txtYear" type="number" />出生月份:<input id="txtMonth" type="number" /><input type="button" onclick="goDead()" value="还能活多久?" /><br /><br /><br /><div id="divL"></div><br /><br /><div id="divHTML" style=""><div> </body> </html>