當柳上原的風吹向天際的時候...

          真正的快樂來源于創造

            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 何楊 閱讀(165) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 顺昌县| 乌兰浩特市| 广河县| 邵东县| 屏山县| 分宜县| 拜泉县| 南投县| 全州县| 涞水县| 错那县| 且末县| 黑水县| 邢台县| 平阳县| 平远县| 罗江县| 霸州市| 太湖县| 平原县| 噶尔县| 湘潭县| 吴川市| 平昌县| 陇南市| 弥渡县| 通城县| 龙山县| 扶沟县| 饶河县| 竹北市| 平利县| 邹城市| 长兴县| 武冈市| 仁寿县| 灵台县| 肇东市| 吉水县| 华宁县| 台中县|