我想用最后一个 tr 替换 tr clicked。我尝试了 ReplaceWith 但它不起作用
$(this).replaceWith('#table_article tr:last');
上下文:
$('#table_article tr').on('click', function(event){
event.preventDefault();
if($(this).attr('id') != undefined){
var $this = $(this);
$.ajax({
type: 'GET',
url : "{% url 'updateligneFacture_temp' %}",
data: $("#form_facture").serialize() + "&ref_article=" + $(this).attr('id'),
success : function(data){
$('#contenue_fact').html(data);
$this.replaceWith('#table_article tr:last');
$('.selectpicker').selectpicker();
},
error : function(){
alert("Erreur update !!");
}
});
}
});
最佳答案
您必须确保包含 jQuery。
此外,请确保在将选择器括在括号中之前放置一个 $
符号。
$("tr").on("click", function() {
$(this).replaceWith($("tr:last").html());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>Apples</td>
<td>$1.00</td>
</tr>
<tr>
<td>Mangos</td>
<td>$1.20</td>
</tr>
<tr>
<td>Oranges</td>
<td>$1.15</td>
</tr>
<tr>
<td>Pineapples</td>
<td>$3.00</td>
</tr>
</table>
关于javascript - 如何将tr替换为最后一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41898809/