<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算面积</title>
</head>
<body>
<form>
<input type="text" name="h" value="" size="20">
<input type="text" name="w" value="" size="20">
<input type="button" name="Submit" value="提交" onClick="multi(this.form.w.value, this.form.h.value)">
</form>
<script language="javascript">
//正方形类
function Rectangle(width, height){
this.width = width;
this.height = height;
}
//算面积
Rectangle.prototype.getArea = function () {
return this.width * this.height;
}function multi(w, h){
//新建对象
var f = document.forms[0]
var rectangle = new Rectangle(parseFloat(w), parseFloat(h));
alert(rectangle.width);
alert(rectangle.getArea());
}
</script>
</body>
</html>