简体   繁体   English

使用JavaScript迭代表格以获取特定单元格的值

[英]Iterate through a table using JavaScript to get values of specific cells

How can I iterate through a table using JavaScript to get the values of cells 4 and 5? 如何使用JavaScript迭代表以获取单元格4和5的值?

This is what I have: 这就是我所拥有的:

function constructString() {    
    var table=document.getElementById('wcList');

    for(var i=0; i<table.rows.length;i++){

        var row       = getElem(RowId + i);
        var str_wc    = table.rows[i].cells[1].firstChild.value;
        var str_act   = table.rows[i].cells[5].firstChild.value;
        var str_coh   = table.rows[i].cells[6].firstChild.value;
        var str_mconf = table.rows[i].cells[7].firstChild.value;

        var string1 = str_wc + row + str_act + row + str_coh + row + str_mconf + row;

     }
}

Use innerHTML . 使用innerHTML

Try this: 尝试这个:

function constructString() {   
    var table=document.getElementById('wcList');

    for(var i=0; i<table.rows.length;i++){

        // FIX THIS
        var row = 0;

        var str_wc=(table.rows[i].cells[1].innerHTML);
        var str_act=(table.rows[i].cells[5].innerHTML);
        var str_coh=(table.rows[i].cells[6].innerHTML);
        var str_mconf=(table.rows[i].cells[7].innerHTML);

        var string1=str_wc +row+str_act+row+str_coh+row+str_mconf+row;

        alert(string1);
     }
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM