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

          真正的快樂來源于創造

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
          以前我們使用JavaScript制作過一個JS類MyTable,用于操作表格,但使用上還是有不便的地方,今天把它修改了一下,增加了幾個類函數和兩個輔助函數,現在更方便一些了。

          JS類MyTable代碼如下:
          /*************************
          *
          *   Class:MyTable
          *   2009.08.22
          *************************
          */
          //-- Contructor
          function MyTable(id){
              
          this.table=$(id);
          }

          //-- Clear Rows except the first
          MyTable.prototype.clear=function(){
              
          while(this.table.rows.length>0){
                  
          this.table.deleteRow(0);
              }
          }

          //-- Append a row to table
          MyTable.prototype.getRowCount=function(){
              
          return this.table.rows.length;
          }

          //-- Append a row to table
          MyTable.prototype.appendRow=function(row){
              
          this.table.appendChild(row);
              
          this.refreshRowColor();
          }

          //-- remove a row to table
          MyTable.prototype.removeRow=function(id){
              
          var delRow=$(id);
              delRow.parentNode.removeChild(delRow);
              
          this.refreshRowColor();
          }

          //-- refresh a row's backgroud-color
          MyTable.prototype.refreshRowColor=function(){
              
          for(var i=0;i<this.table.childNodes.length;i++){
                  
          this.table.childNodes[i].className=((i % 2==1)?"odd":"even");
              }
          }

          //-- create a text cell
          function createTextTd(text){
              
          var cell=document.createElement("td");
              cell.appendChild(document.createTextNode(text));
              
              
          return cell;
          }

          //-- create a link cell
          function createLinkTd(text,url){
              
          var link=document.createElement("a");
              link.appendChild(document.createTextNode(text));
              link.setAttribute(
          "href",url);

              
          var cell=document.createElement("td");
              cell.appendChild(link);
              
              
          return cell;
          }

          取得的效果:


          全體代碼下載(注意CSS文件變更了):
          http://www.aygfsteel.com/Files/heyang/JsTable20090822214752.rar

          posted on 2009-08-22 21:54 何楊 閱讀(344) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 晋宁县| 凤冈县| 饶阳县| 苏州市| 九龙县| 禹州市| 轮台县| 孟津县| 万荣县| 辰溪县| 油尖旺区| 沾益县| 宜州市| 资源县| 宝丰县| 大丰市| 汪清县| 海门市| 雷州市| 淮安市| 沁源县| 香港 | 荔波县| 江源县| 财经| 博罗县| 克什克腾旗| 土默特右旗| 井研县| 泰兴市| 灵武市| 万安县| 塔城市| 开封市| 宜川县| 金秀| 贵德县| 精河县| 历史| 陵川县| 二连浩特市|