我有以下表结构:访问标记通过JavaScript
<table id="currentloc_table">
<tr>
<th></th>
<th>Name</th>
<th>Details</th>
</tr>
<tr>
<td><input id='viewonMapCheckbox' type='checkbox'></td>
<td>
<span class="tooltip" href="#">
<span class="custom info">
<em>
</em>
Last Activity: 2013-03-12 03:29:21<br/>
Latitude: <span id="lat">30</span><br/>
Longitude: <span id="lon">70</span><br/>
</span>
</span>
</td>
<td>Details</td>
</tr>
</table>
我需要使用JavaScript设置纬度和经度值,但不能使它工作。请帮助我。这是我写的代码:
var loc_table = document.getElementById('currentloc_table');
var loc_table_rows_count = document.getElementById('currentloc_table').getElementsByTagName("tr").length;
for (var i = 0; i < loc_table_rows_count; i++) {
if (i > 0) {//skipping header row
var row = loc_table.rows[i];
row.cells[1].firstChild.firstChild.getElementById("lat").innerHTML = "31";
row.cells[1].firstChild.firstChild.getElementById("lon").innerHTML = "71";
}
}
你为什么要使用循环,如果你有单列? – Cris 2013-03-14 13:08:00
@cris可以有多行。我将单行显示为示例数据。 – Azeem 2013-03-14 13:16:55
然后每个纬度和经度都会有相同的ID,请确保您有不同的ID或通过名称 – Cris 2013-03-14 13:29:28