1
HTML;为什么Bootstrap按钮在追加HTML后无法点击?
<div class="col-lg-9" style="background-color:#ffffff; z-index:-1;">
<h2 id="titleH2"></h2>
<div class="table-responsive">
<table class="table table-striped" id="tableId">
<thead>
<tr>
<th>#</th>
<th>Word</th>
<th>Meaning</th>
<th>Type</th>
</tr>
</thead>
<tbody id="tbodyId">
</tbody>
</table>
</div>
</div>
javascript; (加载页面时显示的数据。)
window.onload = function(){
showAllWords();
}
function showAllWords(){
$.ajax({
url: "${pageContext.request.contextPath}/myWords/allWords",
type: "GET",
async:false,
success: function(data) {
$('#tbodyId').empty();
var trHTML = '';
var index = 1;
$.each(data, function() {
trHTML += "<tr>";
$.each(this, function(k, v) {
if(k == "idWord"){
trHTML += "<td>" + index + "</td>";
index++;
}
else{
trHTML += "<td>" + v + "</td>";
}
});
trHTML += "<td>";
trHTML += "<input type=\"submit\" class=\"btn btn-primary\" value=\"Delete\">";
trHTML += "</td>";
});
$('#tbodyId').append(trHTML);
}
});
}
输出:
我无法点击追加HTML后 '删除按钮'。所以,按钮不可点击。我该如何解决这个问题,或者我应该改变什么?
有没有事件处理程序发布,但它可能没有下放,而你每次更换元件,除去事件处理程序,所以你需要委派的事件处理程序。 – adeneo