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

          真正的快樂來源于創(chuàng)造

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
          <html>
           
          <head>
            
          <title>使用混合方式創(chuàng)建類實例</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 何楊 閱讀(164) 評論(0)  編輯  收藏

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 万荣县| 普格县| 大港区| 樟树市| 巩义市| 吐鲁番市| 宁国市| 富宁县| 自治县| 阿拉善左旗| 吴桥县| 怀远县| 康保县| 盐池县| 辽宁省| 凉城县| 景宁| 得荣县| 玉门市| 马边| 余庆县| 凤台县| 靖边县| 博罗县| 武清区| 会同县| 黄骅市| 西华县| 聂拉木县| 徐州市| 合山市| 左权县| 西峡县| 昌黎县| 鄱阳县| 重庆市| 陆河县| 合江县| 玉林市| 吴忠市| 聂荣县|