javascript求圆周长和面积 2、 自定义一个circle对象,其属性r为圆的半径,方法Area的作用是求该圆的面积
1个回答
2010-11-04
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>计算出圆的周长和面积</title>
<script language="javascript">
function circle(r)
{
this.r=r
this.Area=Area
this.Circum=Circum
}
function Circum()
{
return(3.14*2*this.r)
}
function Area()
{
return(3.14*this.r*this.r)
}
r=parseInt(prompt("请输入半径:",""));
var newcircle=new circle(r)
var Circumcapital=newcircle.Circum
var Areacapital=newcircle.Area
document.write("周长:"+newcircle.Circum+"<br>")
document.write("面积:"+newcircle.Area+"<br>")
</script>
</head>
<body>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>计算出圆的周长和面积</title>
<script language="javascript">
function circle(r)
{
this.r=r
this.Area=Area
this.Circum=Circum
}
function Circum()
{
return(3.14*2*this.r)
}
function Area()
{
return(3.14*this.r*this.r)
}
r=parseInt(prompt("请输入半径:",""));
var newcircle=new circle(r)
var Circumcapital=newcircle.Circum
var Areacapital=newcircle.Area
document.write("周长:"+newcircle.Circum+"<br>")
document.write("面积:"+newcircle.Area+"<br>")
</script>
</head>
<body>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |