<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>index</title>
		<meta name="author" content="Administrator" />
		<script type="text/javascript" src="yuan.js"></script>
		<!-- Date: 2015-12-29 -->
		<script type="text/javascript">
			var r = 5;
			var circle = new Circle(r);
			document.write("半径为"+r+"的周长:"+circle.perimeter()+",面积:"+ circle.area());
		</script>
	</head>
	<body>

	</body>
</html>

 yuan.js文件代码:

/**
 * 创建一个对象圆
 * 属性:半径
 * 方法:面积和周长
 * @author Administrator
 */

function Circle(r){
	this.r = r;
}

Circle.prototype.area = function(){
	return this.r * this.r;
};

Circle.prototype.perimeter = function(){
	return 2 * Math.PI * this.r;
};

 

相关文章:

  • 2021-07-04
  • 2021-09-16
  • 2021-10-07
  • 2021-12-13
  • 2022-01-24
  • 2021-09-15
  • 2022-12-23
猜你喜欢
  • 2021-10-16
  • 2021-05-17
  • 2021-09-12
  • 2021-09-29
  • 2021-06-14
  • 2021-09-26
  • 2021-10-15
相关资源
相似解决方案