我想從我的javascript文件中取出一些數據,並將其放入我的html文件中的新行和列。我認爲這個問題可能與我的腳本在我的html文件中的表之前關閉有關。我目前在我的HTML文件中的表格看起來像這樣:使用JS添加行到一個html表格
<div id="map" style="width: 700px; height: 700px"></div>
<script src="js/mapping.js"></script>
<div id="tablebody">
<p>
<b>List of Nearby Locations</b>
</p>
<table class="table table-stripped">
<tbody>
<tr>
<th>Name</th>
<th>Address</th>
</tr>
<tr>
<td>John Smith</td>
<td>1500 Pennsylvania Ave</td>
</tr>
</tbody>
</table>
</div>
和JS代碼,看起來像這樣:
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
alert("name: " + results[i].name + ", Address:" + results[i].vicinity);
$('#tablebody tr:last').after('<tr>"Name: " + results[i].name + ", Address: " + results[i].vicinity</tr>');
}
}
}
完美的作品,謝謝 – user3076590