获得表值

时间:2013-03-30 05:28:33

标签: javascript dom html-table

这应该很简单,但我似乎无法获得<td> Value3

的价值

如何遍历此DOM以从<td>获取值?

<table>
  <thead>
    <tr>
      <th col="value2"></th>
    </tr>
   </thead>
  <tbody>
     <tr id="value1">
       <td>Value3</td>
      </tr>
   </tbody
<table>

我使用以下内容检索其他属性。但似乎无法获得<td>的价值:

        "row_id": this.parentNode.getAttribute('id'),
        "id": this.getAttribute('id'),
        "name": this.getAttribute('row'),
        "project": this.getAttribute('value'),
        "column": oTable.fnGetPosition( this )[2]

我已经尝试了以下以及其他各种没有运气的其他人

$(table tbody tr td).value
document.getElementsByTagName('tr').getAttribute('value')

我的表是通过JSTL动态生成的,如下所示。

            <c:forEach var="column" items="${row}">
                <td><c:out value="${column}"/></td>
            </c:forEach>

3 个答案:

答案 0 :(得分:0)

我认为你的问题是你试图获得价值,但表的内容只是HTML。试试这个:

$('table tbody tr td').html()

答案 1 :(得分:0)

脚本中的值属性用于输入元素。在这种情况下,Value3只是表格单元格内的文本。尝试使用文本getter:

$('td:first').text()

答案 2 :(得分:0)

试试这个:$.each($("table tbody tr td"), function(i,v){alert($(v).text())});