function CirclrArea(r){
var r=window.prompt("请输入数据")/*窗口输入*/
var CirclrArea=r*r*3.14
document.write(CirclrArea)/*窗口输出*/
}
</script>
<body onload="CirclrArea()">/*onload是文件一加载 就执行函数里的代码*/
</body>
</html>
<!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>
<script type="text/javascript">function Circle(x,y,radius){
this.x=x
this.y=y
this.radius=radius
}
Circle.prototype.getDiameter=function(){
return 2*this.radius
}
Circle.prototype.getCircumference=function(){
return Math.PI*2*this.radius
}
Circle.prototype.getArea=function(){
return Math.PI*this.radius*this.radius
}
//test for the object
var circle1=new Circle(10,10,10)
alert(circle1.getDiameter())
alert(circle1.getCircumference())
alert(circle1.getArea())
</script>