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

          真正的快樂來源于創造

            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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 麟游县| 六安市| 凉城县| 石泉县| 博白县| 灵川县| 封开县| 绥芬河市| 喀什市| 玉环县| 博爱县| 永靖县| 石景山区| 铁岭县| 岳阳市| 河源市| 攀枝花市| 蓬溪县| 临泉县| 永寿县| 南城县| 衡东县| 海丰县| 大渡口区| 济源市| 高青县| 廊坊市| 渝北区| 津市市| 太白县| 河间市| 三穗县| 定州市| 鲁山县| 博乐市| 盐山县| 丰原市| 哈尔滨市| 宜昌市| 芦溪县| 南澳县|