编写一个fn()函数,该函数调用后会弹出一个输入框,要求用户输入一个年份,输入以后,程序会提示该年份的2月份有多少天。
你题目的解答代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
</head>
<body>
<script type="text/javascript">
function fn() {
var y = parseInt(prompt("请输入一个年份",""),10);
var d = (y%4==0 && y%100!=0 || y%400==0) ? 29 : 28;
alert(y + "年的2月份有"+d+"天。")
}
fn()
</script>
</body>
</html>
function fn() {
var year = prompt('请输入年份:');
if (isLeapYear(year)) { alert(‘当前年份是闰年,2月份有29天’); }
else { alert('当前年份是平年,2月份有28天'); }
}
function isLeapYear(year) {
var flag = false;
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
flag = true;
}
return flag;
}
fn();
题主要的代码如下,有帮助麻烦点个采纳【本回答右上角】,谢谢~~
function fn() {
var year = Number(prompt("请输入一个年份"));
var isRun = (year % 4 == 0 && year % 100 != 0 )|| year % 400 == 0;
alert(year + '-2月份天数:' + (isRun ? 29 : 28))
}
fn()
function fn() {
var year = prompt('请输入年份:');
var curDate = new Date();
curDate.setYear(year);
curDate.setMonth(2);
curDate.setDate(0);
console.log(curDate.getDate());
alert(year+'年的2月份有'+curDate.getDate()+'天');
}
fn();