JS编写 三角形三边求面积
运用海伦公式,百度百科有,很简单
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<script>
function triangle(){
var a=document.getElementById("a").value*1;
var b=document.getElementById("b").value*1;
var c=document.getElementById("c").value*1;
var p=(a+b+c)/2;
var x=p*(p-a)*(p-b)*(p-c);
var y=Math.sqrt(x);
document.getElementById("s").value=y;
}
</script>
<style>
.font1{
font-family: "微软雅黑";
font-size:40px;
}
#a{
border: 0.5px solid #5891FE;
border-radius: 5px;
width: 500px;
height: 40px;
font-size: 30px;
font-family: "微软雅黑";
}
#b{
border: 0.5px solid #5891FE;
border-radius: 5px;
width: 500px;
height: 40px;
font-size: 30px;
font-family: "微软雅黑";
}
#c{
border: 0.5px solid #5891FE;
border-radius: 5px;
width: 500px;
height: 40px;
font-size: 30px;
font-family: "微软雅黑";
}
#s{
border: 0.5px solid #5891FE;
border-radius: 5px;
width: 500px;
height: 40px;
font-size: 30px;
font-family: "微软雅黑";
}
#button1{
border: 1px solid grey;
width:100px;
height: 50px;
font-size:20px;
font-family: "微软雅黑";
font-weight: bold;
}
</style>
<body><br><br><br><br><br><br><br>
<table width="100%" border="0">
<tbody>
<tr><td align="center"><font class="font1">三角形三边求总面积</font></td></tr>
<tr>
<td align="center"><b class="font1">第一条边为:</b><input type="text" name="a" id="a"></td>
</tr>
<tr>
<td align="center"><b class="font1">第二条边为:</b><input type="text" name="b" id="b"></td>
</tr>
<tr>
<td align="center"><b class="font1">第三条边为:</b><input type="text" name="c" id="c"></td>
</tr>
<tr>
<td align="center"><b class="font1">其总面积为:</b><input type="text" name="s" id="s" readonly></td>
</tr>
<tr>
<td align="center"><input type="button" value="计算" onClick="triangle()" id="button1"></td>
</tr>
</tbody>
</table>
</body>
</html>