用js怎样操作表格?

解决方案 »

  1.   

    You can try Google or Baidu first 
    提问的智慧
      

  2.   

    用DOM
    例如:
    var FileList = $("idFileList"), oFragment = document.createDocumentFragment();
            //用文档碎片保存列表
            Each(rows, function(cells) {
                var row = document.createElement("tr");
                Each(cells, function(o) {
                    var cell = document.createElement("td");
                    if (typeof o == "string") { cell.innerHTML = o; } else { cell.appendChild(o); }
                    row.appendChild(cell);
                });
                oFragment.appendChild(row);
            })
      

  3.   

    用文档对象模型创建结点,详情关注DOM创建与删除结点,关注document类
      

  4.   

    这有实例
    http://download.csdn.net/detail/qq307023807/3936431
      

  5.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
     </head> <body>
      <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
    <form id="form1" name="form1" action="" method="post">
                <td>
                <table cellspacing="0" cellpadding="4" width="100%" border="0" >
                    <tr>
                        <td bgcolor="#C7E8F8">
                            <div align="center"><b>问题 1:</b> </div>
                        </td>
                        <td bgcolor="#C7E8F8">
                            <input size="60" name="Question1" onclick="alert(this.name)" onkeydown="if(event.keyCode==13) addNewQuestion()">
                        </td>
                    </tr>
                </table>
                    <div id="__idInsertBefore"></div>
                    <input type="hidden" value="1" name="newTable">
                    <br/>
                    <div align="right" style="padding:4px">
                        <input type=button onClick="addNewQuestion()" value="增加一个新问题" />
                        <input type="button" value="保存设置" >
                        <input type="reset" value="重新设置"  >
                    </div>
                </td>
    </form>
    </tr>
    </table>
    <script>
    function addNewQuestion()
    {
    document.form1.newTable.value =  parseInt(document.form1.newTable.value) + 1;
    var newItemId;
    if( (document.form1.newTable.value).length > 2 )
    {
    alert("您的调查问题总数不能超过 99 个。")
    window.location.reload();
    }
    newItemId = document.form1.newTable.value;
    var objItem = '<table cellspacing="0" cellpadding="4" width="100%" border="0" >';
    objItem += '  <tr>';
    objItem += '<td bgcolor="#C7E8F8">';
    objItem += '      <div align="center"><b>问题 ' + newItemId + ':</b> </div>';
    objItem += '    </td>';
    objItem += '    <td bgcolor="#C7E8F8">';
    objItem += '      <input size="60" name="Question' + newItemId + '" onclick="alert(this.name)" onkeydown="if(event.keyCode==13) addNewQuestion()">';
    objItem += '    </td>';
    objItem += '  </tr>';
    objItem += '</table>';
    document.all.__idInsertBefore.insertAdjacentHTML("beforeBegin", objItem);
    document.form1.elements["Question" + newItemId].focus()
    }
    function showTips(obj)
    {
    obj.title = obj.value;
    }
    </script> </body>
    </html>
      

  6.   

    http://www.15ae.com/archive/2011-12/13113326472.htmljs 获得table表格的行和删除一行的方法