當(dāng)柳上原的風(fēng)吹向天際的時(shí)候...

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

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
          <html>
           
          <head>
            
          <title>使用混合方式創(chuàng)建類實(shí)例</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)站導(dǎo)航:
           
          主站蜘蛛池模板: 崇信县| 松阳县| 增城市| 紫云| 连城县| 弥勒县| 和政县| 信丰县| 丹巴县| 盖州市| 莱州市| 宁都县| 津市市| 承德县| 伽师县| 凤阳县| 桐梓县| 丰镇市| 新巴尔虎右旗| 寿宁县| 永济市| 高雄市| 广西| 库车县| 西畴县| 余江县| 临城县| 广汉市| 会理县| 凤城市| 堆龙德庆县| 墨竹工卡县| 乐陵市| 乐山市| 尉犁县| 沧源| 辽中县| 齐齐哈尔市| 拉萨市| 平安县| 民丰县|