当柳上原的风吹向天际的时候...

真正的快乐来源于创造

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
<html>
 
<head>
  
<title>使用混合方式创建类实例</title>
 
</head>
  
<body>   
    
<div>
    
<table border="1" class="holder" cellspacing="0" width="300" height="20">
      
<caption>人员名单</caption>
      
<tbody id="personList"> 
        
<TR>
          
<TH width="50">ID</TH>
          
<TH>姓名</TH>
          
<TH width="100">年龄</TH>
        
</TR> 
      
</tbody>
    
</table>
    
</div>
    
<hr/>
    
<div>
      姓名:
<input type="text" name="name"/><br/>
      年龄:
<input type="text" name="age"/><br/>
      
&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="btn" value="提交"/><br/>
    
</div>
  
</body>
</html>
<script language="javascript">
<!--

function $(id){
  
return document.getElementById(id);
}


window.onload
=function(){
  $(
"btn").onclick=function(){
    
var emp=new Employee($("name").value,$("age").value); 
    $(
"personList").appendChild(emp.getInfoLine()); 
    
    $(
"name").value="";         
    $(
"age").value="";
  }

}


var sn=0;

function Employee(name,age){
  sn
++;
  
  
this.name=name;
  
this.age=age;
}


Employee.prototype.getName
=function(){
  
return this.name;
}


Employee.prototype.getAge
=function(){
  
return this.age;
}


Employee.prototype.getInfoLine
=function(){
  
var row=document.createElement("tr");
  row.setAttribute(
"height",20);
 
  
var cell1=document.createElement("td");
  cell1.appendChild(document.createTextNode(sn));
  row.appendChild(cell1); 

  
var cell2=document.createElement("td");
  cell2.appendChild(document.createTextNode(
this.name));
  row.appendChild(cell2); 

  
var cell3=document.createElement("td");
  cell3.appendChild(document.createTextNode(
this.age));
  row.appendChild(cell3); 

  
return row;
}

//-->
</script>
posted on 2009-02-24 16:08 何杨 阅读(153) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: