3

如何使用 JavaScript 遍历表以获取单元格 4 和 5 的值?

这就是我所拥有的:

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;

     }
}
4

1 回答 1

1

使用innerHTML.

尝试这个:

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);
     }
}  
于 2013-01-29T16:31:15.040 回答