我想用JS或HTML代码完成以下计算公式,自动生成计算结果,应该怎么办?
发布网友
发布时间:2022-05-29 08:37
我来回答
共1个回答
热心网友
时间:2023-10-13 01:11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="number">
<input type="number">
<button>按钮</button>
<p></p>
</body>
<script>
let pText = document.querySelector("p");
document.querySelector("button").onclick = () => {
let num1 = document.querySelector("input").value;
let num2 = document.querySelectorAll("input")[1].value
if (num1 <= 300) {
pText.innerHTML = "应大于300"
} else {
let result = parseInt((num1 / 6 - num2) * 0.04 * 27);
if (result < 0) {
pText.innerHTML = 0;
} else if (result > 500) {
pText.innerHTML = 500;
} else {
pText.innerHTML = result
}
}
}
</script>
</html>
请采纳