Javascript - get all table -> tr values

前端 未结 8 1687
鱼传尺愫
鱼传尺愫 2020-12-28 23:02
8条回答
  •  有刺的猬
    2020-12-28 23:39

    var rows = document.getElementsByTagName("table")[0].rows;
    var last = rows[rows.length - 1];
    var cell = last.cells[0];
    var value = cell.innerHTML
    

    Try it yourself here: http://jsfiddle.net/ReyNx/.

    Obviously you'll have to change document.getElementsByTagName("table")[0] to appropriately match your table

    If you're using jQuery it's easier:

    var value = $('table tr:last td').text();
    

    For more info, see the MDN DOM reference, which shows you which properties are available on which elements to traverse the DOM.

提交回复
热议问题
foo
bar
abc@yahoo.com