js實現動態表格

js代碼:

function addtable(){
            var trHtml="<tr><td><input type='checkbox' name='ckb'></td>"+
            "<td><input type='text' name='' style='width:100%;height:100%'></td>"+
            "<td><input type='text' name='' style='width:100%;height:100%'></td>"+
            "<td><input type='text' style='width:100%;height:100%'></td>"+
            "<td><input type='text' style='width:100%;height:100%'></td>"+
            "<td><input type='text' style='width:100%;height:100%'></td></tr>";
            alert(trHtml);
            var table = document.getElementById("fangjiantable");
            NewRow = table.insertRow();
            NewRow.innerHTML = trHtml;
        }
        function deletetable(){
            var tb = document.getElementById("fangjiantable");
            var selectBox = document.getElementsByName("ckb");  
            for(var i=selectBox.length;i>1;i--){
                if(selectBox[i-1].checked){
                    tb.deleteRow(i);
                }
            }
        }

頁面組件:

<table id="fangjiantable" border=0 cellpadding=1 cellspacing=1 class="form_table" width="95%" align="center" >
              <tr>
                   <th nowrap><div align="left"></div></th>
                   <th nowrap><div align="left">房間號</div></th>
                   <th nowrap><div align="left">房間名稱</div></th>
                   <th nowrap><div align="left">房間用途</div></th>
                   <th nowrap><div align="left">使用面積</div></th>
                   <th nowrap><div align="left">資產編號</div></th>
             </tr>
        </table>
        <table align="center">
            <tr>
                <td align="center">
                    <a href="#" class="easyui-linkbutton" data-options="plain:false,iconCls:'icon-save'" onclick="kongFangPublish()" >保存</a>
                    <a href="#" class="easyui-linkbutton" data-options="plain:false,iconCls:'icon-cancel'" onclick="kongFangchakan()" >關閉</a>
                </td>
            </tr>
        </table>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章