var zc=2*3.1415926*r
var mj=3.1415926*r*r
console.log('圆的周长为:'+zc)
console.log('圆的面积为:'+mj)
}
circle(2)
输入半径r即可输出对应周长和面积
<!doctype html><html>
<head>
<title>CZT4-3</title>
</head>
<script>
function randomR( )
{
var m=Math.floor(Math.random()*20)+1
document.myform.r.value=m
}
function compute( )
{
var radius=document.myform.r.value
if (isNaN(radius)==false &&radius.length!=0)
{
var C,S
C=2*Math.PI*parseFloat(radius)
S=Math.PI*Math.pow(radius,2)
C=Math.round(C*100)/100
S=Math.round(S*100)/100
document.myform.c.value=C
document.myform.s.value=S
}
else
alert("请输入半径,必须为数字!")
}
</script>
<body>
<form name="myform" id="myform">
半径:<input name="r" type="text"><br>
周长:<input name="c" type="text"><br>
面积:<input name="s" type="text"><br>
<input name="calC" type="button" value="随机半径" onClick="randomR( )">
<input name="calS" type="button" value="计算结果" onClick="compute( )">
</form>
</body>
</html>