用html设计一个计算圆的周长、面积的页面。在文本框中输入圆的半径,单击“计算”按钮,将计算结果圆的周长、面积分别显示在两个对应的文本框里。圆的周长和面积保留两位小数。
时间: 2024-06-14 21:04:01 浏览: 10
以下是一个用HTML设计计算圆的周长和面积的页面的示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>计算圆的周长和面积</title>
<script>
function calculate() {
var radius = parseFloat(document.getElementById("radius").value);
var circumference = 2 * Math.PI * radius;
var area = Math.PI * radius * radius;
document.getElementById("circumference").value = circumference.toFixed(2);
document.getElementById("area").value = area.toFixed(2);
}
</script>
</head>
<body>
<h1>计算圆的周长和面积</h1>
<label for="radius">请输入圆的半径:</label>
<input type="number" id="radius" step="0.01">
<button onclick="calculate()">计算</button>
<br><br>
<label for="circumference">圆的周长:</label>
<input type="text" id="circumference" readonly>
<br><br>
<label for="area">圆的面积:</label>
<input type="text" id="area" readonly>
</body>
</html>
```