直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no,
initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>延时器</title>
<style>
</style>
</head>
<body>
<input type="button" id="btn" value="发送">
<script>
var btn = document.getElementById('btn')
btn.onclick = function () {
this.disabled = true;
var n = 30;
var timer = setInterval(function () {
btn.value = `还剩${n--}秒`;
if (n < 0) {
clearInterval(timer);
btn.disabled = false;
btn.value = '发送';
}
}, 1000)
}
</script>
</body>
</html>
判断一个人的年龄是否满十八
var age = 25;
if (age >= 18) {
console.log('你可以看小电影了');
} else {
console.log('您还有' + (18 - age) + '年可以看小电影');
}
判断一个年份是闰年还是平年
闰年:能被4整除,但不能被100整除的年份 或者 能被400整除的年份
var year = parseInt(prompt('请输入年份'))
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
console.log(year + '是闰年');
} else {
console.log(year + '是平年');
}