如何用JS取表格单元格的值以及如何给它赋值。表格、单元格的属性用的都是id,不是name

解决方案 »

  1.   

    <html:text>然后根據id去取?
    難道document。getElementById?
    還是document。forms【0】。字段名。value?
    或者var xx = $F(‘字段名’)?
    你到底要干什么?
      

  2.   

    document。getElementById
    就可以了
      

  3.   


    function makeTable() {       var table = document.createElement("table");       table.setAttribute("border","1");       table.setAttribute("width","600");       table.setAttribute("class","tab-content");       document.body.appendChild(table);       var header = table.createTHead();       var headerrow = header.insertRow(0);       headerrow.insertCell(0).appendChild(document.createTextNode("姓名"));       headerrow.insertCell(1).appendChild(document.createTextNode("职业"));       headerrow.insertCell(2).appendChild(document.createTextNode("工资"));
           for(var i=0;i<5;i++) {              var row = table.insertRow(i+1);              row.insertCell(0).appendChild(document.createTextNode("aaa"));              row.insertCell(1).appendChild(document.createTextNode("bbb"));              row.insertCell(2).appendChild(document.createTextNode("ccc"));
           }}  调用 makeTable() 这个方法就可以创建一个 Table , 数据可以从 XML 或者 其他文件,数据库里将值取出来读取到表格中
      

  4.   

    表格有rows 及 cells属性
    先得到表格的对象 用 document.getElementById(tableid) 或 document.all.tableid 来获取
    再定位到你要获取单元格 table.rows(i).cells(j).innerText 
      

  5.   


    document.all.表格ID.rows[x].cells[x].innerHTML="";
    x為數字型,