<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>计算年终奖</title>
</head>
<body>
工龄:<input type="text" value="1" id="workYear">
<br>
薪资:<input type="text" value="14000" id="workMoney">
<br>
<button id="submit">计算年终奖</button>
<br>
你的年终奖是:¥<span id="valBox"></span>
<!--IMPORT JS-->
<script>
let workYear = document.getElementById('workYear');
let workMoney = document.getElementById('workMoney');
let submit = document.getElementById('submit');
let valBox = document.getElementById('valBox');
submit.onclick = function () {
//1、获取文本框的信息
// 文本框.value获取输入的内容,格式是字符串
let year = Number(workYear.value);
let money = Number(workMoney.value);
//判断输入是否非法
if (isNaN(year) || isNaN(money)) {
alert("输入的内容是非法格式");
return;
}
//2、经过逻辑处理,计算出结果
let result = null;
if (year < 1) {
result=money>8000?money*1.2:money;
} else if (year >= 1 && year <2) {
result=money>10000?money*1.7:money*1.5;
} else {
result=money>12000?money*3.2:money*3;
}
//3、把结果赋值给#valBox即可
valBox.innerHTML=result;
}
</script>
</body>
</html>
二十三、计算年终奖
最新推荐文章于 2022-01-15 10:48:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)