用html写一个计算鸡兔的个数,鸡兔共35个头,94只脚
时间: 2023-06-11 12:06:50 浏览: 57
下面是一个简单的 HTML 代码,实现了计算鸡兔个数的功能:
```html
<!DOCTYPE html>
<html>
<head>
<title>计算鸡兔个数</title>
</head>
<body>
<h1>计算鸡兔个数</h1>
<form>
<label>头的数量:</label>
<input type="text" id="head" name="head"><br><br>
<label>脚的数量:</label>
<input type="text" id="foot" name="foot"><br><br>
<input type="button" value="计算" onclick="calculate()"><br><br>
<label>鸡的数量:</label>
<input type="text" id="chicken" name="chicken" readonly><br><br>
<label>兔的数量:</label>
<input type="text" id="rabbit" name="rabbit" readonly><br><br>
</form>
<script>
function calculate() {
var head = parseInt(document.getElementById('head').value);
var foot = parseInt(document.getElementById('foot').value);
var chicken = 0;
var rabbit = 0;
rabbit = (foot - head * 2) / 2;
chicken = head - rabbit;
document.getElementById('chicken').value = chicken;
document.getElementById('rabbit').value = rabbit;
}
</script>
</body>
</html>
```
这个 HTML 页面包含一个表单,用户需要输入头和脚的数量,然后点击“计算”按钮,就可以计算出鸡和兔的数量。JavaScript 函数 `calculate()` 将从表单中获取头和脚的数量,然后根据鸡和兔的脚数推算出它们的数量。最后,将计算结果填入表单中,显示给用户。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![md](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)