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

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

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks


          <html>
           
          <head>
            
          <title>表單控件運用完整實例</title>
           
          </head>
            
          <body>   
              
          <div>
              
          <table border="1" class="holder" cellspacing="0" width="100%" height="20">
                
          <caption>雇員名單</caption>
                
          <tbody id="personList"> 
                  
          <TR>
                    
          <TH>姓名</TH>
                
          <TH>性別</TH>
                
          <TH>籍貫</TH>
                
          <TH>職位</TH>
                
          <TH>簡介</TH>          
                  
          </TR> 
                
          </tbody>
              
          </table>
              
          </div>
              
          <hr/>
              
          <div>
                姓名:
          <input type="text" name="name"/><br/>
              性別:
          <input type="radio" name="sex" value="男" checked/>男/<input type="radio" name="sex" value="女"/><br/>
              籍貫:
          <select name="nativePlace">
                  
          <option value="遼寧" >遼寧</option>
                  
          <option value="北京" >北京</option>
                  
          <option value="上海" >上海</option>
                  
          <option value="湖南" selected>湖南</option>
                 
          </select><br/>
              職位:
          <INPUT TYPE="checkbox" NAME="title" value="程序員">程序員</input>
                     
          <INPUT TYPE="checkbox" NAME="title" value="高程">高程</input>
                     
          <INPUT TYPE="checkbox" NAME="title" value="TL">TL</input>
                     
          <INPUT TYPE="checkbox" NAME="title" value="PL">PL</input>
                     
          <INPUT TYPE="checkbox" NAME="title" value="GM">GM</input><br/>
                簡介:
          <textarea name="intro" rows="10" cols="40"></textarea><br/>
                
          &nbsp;&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,
                        
          new RadioButton("sex").getSelectedValue(),
                        $(
          "nativePlace").value,
                        
          new CheckBoxButton("title").getSelectedValues(),
                        $(
          "intro").value
                       ); 


              $(
          "personList").appendChild(emp.getInfoLine()); 
              
              $(
          "name").value="";         
            $(
          "intro").value="";
            }

          }


          var sn=0;

          function Employee(name,sex,nativePlace,titles,intro){
            
          this.name=name;
            
          this.sex=sex;
            
          this.nativePlace=nativePlace;

            
          this.title="";
            
          for(var i=0;i<titles.length;i++){
              
          this.title+=titles[i]+",";
            }


            
          this.intro=intro; 
          }


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

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

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

            
          var cell4=document.createElement("td");
            cell4.appendChild(document.createTextNode(
          this.title));
            row.appendChild(cell4); 

            
          var cell5=document.createElement("td");
            cell5.appendChild(document.createTextNode(
          this.intro));
            row.appendChild(cell5); 

            
          return row;
          }


          /*********************************************
          * 單選框類
          ********************************************
          */

          function RadioButton(name){
            
          this.name=name;  
          }


          RadioButton.prototype.getSelectedValue
          =function(){
            
          var arr=document.getElementsByTagName("input");

            
          for(var i=0;i<arr.length;i++){
              
          if(arr[i].name==this.name && arr[i].checked){
                
          return arr[i].value;
              }

            }


            
          return null;
          }


          /*********************************************
          * 復(fù)選框類
          ********************************************
          */

          function CheckBoxButton(name){
            
          this.name=name;  
          }


          // 得到復(fù)選框的選擇項,返回值為用戶選中的數(shù)組,返回空表示用戶未選中選項
          CheckBoxButton.prototype.getSelectedValues=function(){
            
          var arr=document.getElementsByTagName("input");
            
          var selectedArr=new Array;
            
          var index=0;

            
          for(var i=0;i<arr.length;i++){
              
          if(arr[i].name==this.name && arr[i].checked){
                  selectedArr[index
          ++]=arr[i].value;
              }

            }


            
          return selectedArr;
          }


          //-->
          </script>

          posted on 2009-03-16 12:46 何楊 閱讀(318) 評論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 渝中区| 翼城县| 司法| 志丹县| 剑阁县| 高密市| 桃源县| 武清区| 磐石市| 石棉县| 鸡西市| 昭平县| 普洱| 同江市| 佛山市| 林周县| 阜城县| 潜江市| 贵州省| 泽库县| 青田县| 泰和县| 利川市| 右玉县| 盘山县| 蚌埠市| 克什克腾旗| 志丹县| 涟水县| 呼和浩特市| 乌拉特前旗| 沙河市| 永胜县| 米林县| 渑池县| 霸州市| 乐安县| 垫江县| 达拉特旗| 玉溪市| 福海县|