JavaScript删除页面上的所有唯一图像

时间:2016-05-07 20:37:08

标签: javascript image compare

我正在尝试制作将删除某个页面上所有唯一图片的用户脚本。所以我需要比较所有链接并删除每个唯一的链接。我试图这样做:

var images = document.getElementsByTagName('img');

for(i = 0;i < images.length; i++){
   for(j = 0;j < images.length; j++){
       if(images[i].src.!(match(images[j])) images[i].remove()
}

或者用&#34; display:none&#34;

隐藏它

3 个答案:

答案 0 :(得分:1)

    function hideUnique() {
        var imgs = document.getElementsByTagName('img');
        var srcs = [];
        for (var i = 0, n = imgs.length; i < n; i++) {
            srcs[imgs[i].src] = (srcs[imgs[i].src] || 0) + 1;
        }
        for (var i = 0, n = imgs.length; i < n; i++) {
            if (srcs[imgs[i].src] == 1)
                imgs[i].style.display = 'none';
        }

    }

答案 1 :(得分:0)

这与您的代码类似。

var images = document.getElementsByTagName("img");
var arr = [];
for(x in images){
    If(arr.indexOf(images[x].src) == -1){
           arr.push(images[x].src);
    }else
            images[x].style.display = "none";
    }
}

答案 2 :(得分:0)

你可以试试这个

int main() {
float inputr, radius, x, y, z;
Sphere sphere;
double SurfaceArea = sphere.GetSurfaceArea();
char open = '(';
char close = ')';
char comma = ',';
cout << "Please input the center of the sphere in the fashion (X,Y,Z) and press enter: ";
cin >> open >> x >> comma >> y >> comma >> z >> close;
cout << "Please define the radius of the sphere: ";
cin >> inputr;
sphere.DefineCoordinates(x, y, z);
sphere.DefineRadius(inputr);
double Volume = sphere.GetVolume();
cout << "This sphere has a center of (" << sphere.GetX() << ", " << sphere.GetY() << ", " << sphere.GetZ() << ")." << endl;
cout << "This sphere has a radius of " << inputr << "." << endl;
cout << "This computes to a volume of " << Volume << " units cubed, and a surface area of " << SurfaceArea << "." << endl;
}