感觉公式没有错,但是就是不现实结果,求指点
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>円と多辺形の運算</title>
</head>
<script>
function calculate(){
var outarea = document.getElementById('newarea');
var r = document.getElementById('R').value;
var tp = Math.sqrt(3) * r;
var ta = (3 * Math.sqrt(3)) * Math.pow(r,2) / 4;
outarea.innerHTML = "内接正三角形的一边长 : " + tp.toString() + "<br>" + "内接正三角形的面积: " + ta.toString();
}
</script>
<body>
<h4>输入圆的半径</h4>
R=
<input type="text" id="R">
<input type="button" value="计算" onclick="calculate()">
<div id="newarea"></div>
</body>
</html>
是没错,但复制下来运行,似乎onclick事件没绑定对,也许是字符有问题
将你计算按钮那一行替换成这一行代码试试
<input type="button" value="计算" onclick="calculate()">
如有帮助请采纳回答 谢谢