find a value of table cell

萝らか妹 提交于 2019-11-26 18:41:18

问题


<tbody id="contacttable">
</tbody>
<script> 
  var hrtypeCode = document.getElementById('hrtypeCode').value;
  var hrCode = document.getElementById('hrCode').value;
  var hrName = document.getElementById('hrName').value;
  var hrDesc = document.getElementById('hrDesc').value;
  for(i=0;i<hrCode.length; i++){        
    if(hrCode[i]!="") {
      var table = document.getElementById("contacttable");
      var slNo = table.rows.length;
      var tr = table.insertRow(slNo-1);
      tr.id = 'list_tr_' + slNo;
      tr.innerHTML ='<td><input type="text" name="hrtypeCode" value="'+hrtypeCode[i]+'" ></td><td><input type="text" name="hrCode" value="'+hrCode[i]+ '"></td><td><input type="text" name="hrName" value="'+hrName[i]+'" ></td>';
      count++;
    }
  }
</script> 
<i>

how to find out the cell values.i have tried the following code but it showing entire TD row

tbl.rows[i].cells[j].innerHTML);
  alert(tbl.rows[i].cells[j].innerHTML);  

Kindly help in finding the value.. thanks.


回答1:


Table cells don't have values, only input elements do. You need to access the <input> element within the table cell.

Use:

tbl.rows[i].cells[j].getElementsByTagName("input")[0].value

DEMO



来源:https://stackoverflow.com/questions/24745293/find-a-value-of-table-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!