目前脚本
$(function() {
function update() {
$.ajax({
type:"GET",
url:"balancefetch.php",
dataType:"html",
success: function(response){
var trimmedResponse = $.trim(response.replace(/\s+/, ''));
if (trimmedResponse != $("#response1").html()) {
$("#response1").fadeOut(200, function() {
$("#response1").html(response);
$("#response1").fadeIn();
});
}
else {
}
}
});
}
获取一些回复和更新
<span id="response1">Loading...</span>
每当我尝试添加具有相同ID的相同span时,它可以更新两者,它只会更新第一个。我怎样才能更新两个相同的跨度? TIA
答案 0 :(得分:1)
试试这个:
$(function() {
function update() {
$.ajax({
type:"GET",
url:"balancefetch.php",
dataType:"html",
success: function(response){
var trimmedResponse = $.trim(response.replace(/\s+/, ''));
if (trimmedResponse != $(".response1").html()) {
$(".response1").fadeOut(200, function() {
$(".response1").html(response);
$(".response1").fadeIn();
});
}
else {
}
}
});
}
<span class="response1">Loading...</span>