1
我有一些jQuery代碼,每次提交表單時都會替換div中的數據。由於某種原因,replaceWith
函數只能代替div
一次?誰能告訴我我錯過了什麼?jQuery爲什麼replaceWith只能運行一次?
HTML
<div class="count"></div>
jQuery的
$(document).ready(function(){
$("#like_unlike").submit(function(e) { //Second Form
e.preventDefault();
var url = "update_likes.php"; //Grab URL from form
var formdata = $(this).serialize();
console.log(formdata);
$.post(url, formdata, function(response) {
//Post the form
$('.count').replaceWith(response);
});
});
});
表兄弟姐妹只有一個有'.count'?或者你的目標是所有的計數。 –
你的'response'包含一個'.count'類嗎? – Dekel
那麼......你正在更換.count--替換之後,沒有那個類的元素了吧? – sinisake