Getting value from table cell in JavaScript…not jQuery

后端 未结 12 1133
后悔当初
后悔当初 2020-12-02 18:19

I can\'t believe how long this has taken me but I can\'t seem to figure out how to extract a cell value from an HTML table as I iterate through the table with JavaScript. I

12条回答
  •  鱼传尺愫
    2020-12-02 19:11

    A few problems:

    • The loop conditional in your for statements is an assignment, not a loop check, so it might infinite loop

    • You should use the item() function on those rows/cells collections, not sure if array index works on those (not actually JS arrays)

    • You should declare the row/col objects to ensure their scope is correct.

    Here is an updated example:

    var refTab=document.getElementById("ddReferences") 
    var  ttl; 
    // Loop through all rows and columns of the table and popup alert with the value 
    // /content of each cell. 
    for ( var i = 0; i

    Replace innerText with innerHTML if you want HTML, not the text contents.

提交回复
热议问题