<table id="theTable_1" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td align="left" width="20%">Animal weight:</td>
<td align="left"><input type="text" id="inputObj_x_id" name="inputObj_x_name" value="1" title="必须输入0-9999内的数字"/></td>
</tr>
<tr>
<td> </td>
<td align="left" width="20%">Bird weight:</td>
<td align="left"><input type="text" id="inputObj_y_id" name="inputObj_y_name" value="10" title="必须输入0-9999内的数字"/></td>
</tr>
<tr>
<td> </td>
<td align="left" width="20%">People weight:</td>
<td align="left"><input type="text" id="inputObj_z_id" name="inputObj_z_name" value="100" title="必须输入0-9999内的数字"/></td>
</tr>
<tr>
<td colspan="3">
<input type="button" class="button" onclick="viewResult() ;" value="查看结果" />
<input type="button" class="button" onclick="removeConsole();" value="清除控制台" />
</td>
</tr>
</table>
<br>
<br>
<table id="theTable_2" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="headRow">
<td>console[信息台]</td>
</tr>
</table>
<br>
</BODY>
<div id="console_id" style="height:150;overflow-y:auto;width:100%;"></div>
<SCRIPT language="javascript">
var inputObj_x = document.getElementById("inputObj_x_id");//x input object
var inputObj_y = document.getElementById("inputObj_y_id");//y input object
var inputObj_z = document.getElementById("inputObj_z_id");//z input object
var consoleObj = document.getElementById("console_id");//console div object
//打印信息到控制台
function printMsg2Console(message,color){
if(message == 'undefined') return;
if(!color) color = 'black';
if(consoleObj == 'undefined')
consoleObj = document.getElementById("console_id");
var newChild = document.createElement("<span>");
newChild.innerText = message;
consoleObj.appendChild( newChild );
newChild = document.createElement("<br>");
consoleObj.appendChild( newChild );
newChild.scrollIntoView(true);
}
//清除控制台的信息
function removeConsole(){
if(consoleObj == 'undefined')
consoleObj = document.getElementById("console_id");
consoleObj.innerHTML = "";
}
//查看 动物, 鸟, 人 对象的结果
function viewResult(){
//打印全局变量 以及 函数执行结果
var x = inputObj_x.value;
var y = inputObj_y.value;
var z = inputObj_z.value;
var animal = new Animal(x);
var bird = new Bird(y);
var people = new People(z);
var result = "animal \tweight = " + animal.weight + "; eat = " + animal.eat() + "; move = " + animal.move()
+ "\nbird \t\t\tweight = " + bird.weight + "; eat = " + bird.eat() + "; move = " + bird.move()
+ "\npeople \tweight = " + people.weight + "; eat = " + people.eat() + "; move = " + people.move();
printMsg2Console(result, "black");
}
</SCRIPT>
</HTML>