【发布时间】:2020-08-06 04:27:42
【问题描述】:
我看过类似的问题,但他们说这是因为 js 在 html 之前被调用,但我认为在我的代码中,一旦加载了所有 html,就会调用元素。
<table id="UserCards">
<tr>
<th width=20%><strong>Card Holder</strong></th>
<th width=20%><strong>Card Number</strong></th>
<th width=10%><strong>Expiry Date</strong></th>
<th width=10%><strong>CVC</strong></th>
<th width="5%"></th>
</tr>
{% for row in rows %}
<tr>
<td id="name">{{ row['CardName']}}</td>
<td id="number">****************</td>
<td class="realnumber" style="display:none;">{{ row['CardNo'] }}</td>
<td id="date">{{ row['CardExpDate'] }}</td>
<td id="code">***</td>
<td id="realcode" style="display:none;">{{ row['CardSecretCode'] }}</td>
<td><a href="#" class="delete-row" onclick="deleteThis(this)"><span class="fas fa-trash-alt"></span></a></td>
</tr>
{% endfor %}
</table>
function deleteThis(obj){
var cardnumber = $(obj).siblings('.realnumber')[0].textContent;
$(obj).closest('tr').remove();
$.ajax({
type: 'POST',
url: "{{ url_for('deleterow') }}",
contentType: "application/json",
data: JSON.stringify({ number: cardnumber }),
dataType: "json",
success: function(response){
window.location.href = 'http://127.0.0.1:5000/Drunkfy/Home/Paymentdetails';;
},
error: function(error){
console.log(error);
}
});
}
【问题讨论】:
-
您似乎正在删除带有
$(obj).closest('tr').remove()的<tr>,这意味着带有id="realnumber"的<tr>中的元素也将被删除。你看到那里的问题了吗? -
只是我,还是其他人关心将完整的卡片细节渲染到 DOM 中?
-
它不会处理真实数据,它只是用于我需要为学校做的一个项目。渲染需要更高级的知识
标签: javascript html