【发布时间】:2018-01-15 06:28:14
【问题描述】:
我的表格被追加而不是更新。更新html的适当方法是什么。我尝试使用answer from a similar stackoverflow question,但没有成功。
这是我的网页,它使用 Bootstrap 和相关的 ajax:
<div class="bs-component">
<table class="table table-striped table-hover ">
<thead>
<tr>
<th style="font-size: 25px">Week <span id="week" style="font-size: 28px">1</span></th>
<th>12 am - 8 am</th>
<th>8 am - 12 pm</th>
<th>12 pm - 4 pm</th>
<th>4 pm - 8 pm</th>
<th>8 pm - 12 am</th>
</tr>
</thead>
<tbody>
<script>
function loadWeek (x) {
$.post("weekly.php", {p: x}, function (res) {
//$("tbody").append(res);
$('#bs-component table > tbody:last').find('tr:first').before(res);
});
}
$(function () {
loadWeek (1);
});
</script>
</tbody>
</table>
这里是ajax调用的php回显的html
for ($i = 0; $i < 7; $i++) {
echo "<tr><td>$weekDays[$i]</td>";
for ($j = 0; $j < 5; $j++) {
echo "<td><p>".$usersNames[$i][$j]."</p></td>";
}
echo"</tr>";
}
【问题讨论】:
-
"这里是 ajax 调用的 php 回显的 html" 那是 PHP,不是 HTML。你试过
replaceWith()或replaceAll()吗? -
@j08691 不,我没有尝试过 replaceWith() 或 replaceAll()。我将如何使用这些?
标签: php jquery html ajax html-table