我正在制作一个非常简单的系统来记录预订,除了静态的“预订号码”和“价格”部分之外,所有内容都是可编辑的。预订号码是预先定义的,价格是一个变量,取决于“所选座位数量”列的值。当我打开 .html 文件时,“价格”列始终显示为未定义,并且我想在相应编辑“所选座位数”后刷新代码。乘数的价格也是预先定义的和静态的,这意味着当定义了选择的座位数时,它将乘以 5。这是我的代码:
<script type="text/javascript">
var seatvar = document.getElementsByClassName("seatchosen");
var pricepay = seatvar * 5
</script>
<script type="text/javascript">
function RefreshTable () {
var table = document.getElementById ("bookingtable");
table.refresh ();
}
</script>
<table class="editabletable" id="bookingtable" border="1">
<tr><th>Booking Number</th>
<th>Name</th>
<th>Number of Seats Chosen</th>
<th>Seats Chosen</th>
<th>Price</th>
</tr>
<tr><td>1</td>
<td><div contenteditable></div></td>
<td class="seatchosen"><div contenteditable></div></td>
<td><div contenteditable></div></td>
<td><script type="text/javascript">document.write(pricepay);</script></td></tr>
</table>
<p>Price Per Seat: £5</p>
<button onclick="RefreshTable()">Refresh the table</button>
该表仅显示一行,尽管有二十行,它们都遵循相同的代码。我也包含了标题。我不明白为什么我编辑了所选座位数的值后不刷新。
最佳答案
试试这个代码,
在成功函数的位置给出您的 ID。
JS
$('.editabletable').click(function () {
$.ajax({
url: $(this).data("url"),
type: 'GET',
cache: false,
success: function (result) {
$('#your_id').html(result);
}
});
return false;
});
关于javascript - 编辑 HTML 表格后如何刷新它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22938590/