我正在尝试找到一种快速简便的方法来使用 jQuery 删除页面上的重复图像。
我有一组图像被拉进来,大多数是重复的或具有相同的 url。
我在这里尝试了解决方案:Filtering duplicate img src with jQuery unique or remove,但它似乎不起作用。
有没有人做过类似的事情?
PHP:
public function getWeeklyTrackChartGrid($methodVars) {
// Check for required variables
if ( !empty($methodVars['group']) ) {
$vars = array(
'method' => 'group.getweeklytrackchart',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ( $call = $this->apiGetCall($vars) ) {
$i = 0;
$loopN = $call->weeklytrackchart->track;
foreach ($loopN as $track ) {
require 'config.php';
//if(++$i > $userLimit*2) break;
$albumArtS = $tracks['album']['image']['small'] = (string) $track->image[0];
$albumArtM = $tracks['album']['image']['small'] = (string) $track->image[1];
$albumArtL = $tracks['album']['image']['small'] = (string) $track->image[2];
$playCounts = $tracks[$i]['playcount'] = (string) $track->playcount;
?>
<?php if ($playCounts > 1) { ?>
<?php if ($albumArtL) { ?>
<img src="<?php echo $albumArtL; ?>" />
<?php } ?>
<?php } else { ?>
<?php if ($albumArtM) { ?>
<img src="<?php echo $albumArtM; ?>" />
<?php } ?>
<?php } ?>
<?php if ($albumArtwork == "yes") { ?>
<?php if ($albumArt) { ?>
<?php } }?>
<?php $i++;
}
return $tracks;
}
else {
return FALSE;
}
}
else {
// Give a 91 error if incorrect variables are used
$this->handleError(91, 'You must include a group variable in the call for this method');
return FALSE;
}
}
jQuery:
$(function(){
var srcs = [],
temp;
$("img").filter(function(){
temp = $(this).attr("src");
if($.inArray(temp, srcs) < 0){
srcs.push(temp);
return false;
}
return true;
}).remove();
});