gpt4 book ai didi

javascript - 如何使用javascript连续追加12张图像

转载 作者:行者123 更新时间:2023-11-28 08:01:44 25 4
gpt4 key购买 nike

function stripTags(s, n) {
return s.replace(/<\/?(?!br\s*\/?)[a-z][a-z0-9]*[^<>]*>/ig, "").split(/\s+/).slice(0, n - 1).join(' ');
}

function rm(a, b, c) {
var p = document.getElementById(a);
var summ = summary;
var summ = summary;
imgtag = "";
var i = 0;
img = p.getElementsByTagName("img");
imgsrc = img[i].src;
var q = document.getElementById(b);
var r = document.getElementById(c);

for (var i = 0; i < img.length; i++) {
if (img.length >=12) imgtag = '<a class="featured_gallery" href="' + imgsrc + '"><img src="' + imgsrc + '" /></a>';
else if (img.length >=8) imgtag = '<a class="featured_gallery" href="' + img[0].src + '"><img src="' + img[0].src + '" /></a><a class="featured_gallery" href="' + img[1].src + '"><img src="' + img[1].src + '" /></a><a class="featured_gallery" href="' + img[2].src + '"><img src="' + img[2].src + '" /></a><a class="featured_gallery" href="' + img[3].src + '"><img src="' + img[3].src + '" /></a><a class="featured_gallery" href="' + img[4].src + '"><img src="' + img[4].src + '" /></a><a class="featured_gallery" href="' + img[5].src + '"><img src="' + img[5].src + '" /></a><a class="featured_gallery" href="' + img[6].src + '"><img src="' + img[6].src + '" /></a><a class="featured_gallery" href="' + img[7].src + '"><img src="' + img[7].src + '" /></a>';
else if (img.length >= 1) imgtag = '<a href="' + y + '"><img src="' + img[0].src + '" style="max-width:100%;" alt="' + x + '" /></a>';
else imgtag = '<div class="no-img"/>';
}
}

这是我一直用来从帖子内部以图库形式获取图像的代码,其中至少包含 12 张图像。

但它在结果中只显示一张图像

<a href="http://3.bp.blogspot.com/-J3qrDYeQH4U/U-rj0I955_I/AAAAAAAAG7E/ZLvcdGFVVRc/s1600/12.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-J3qrDYeQH4U/U-rj0I955_I/AAAAAAAAG7E/ZLvcdGFVVRc/s1600/12.jpg" height="213" width="320"></a>

但是我想像这样连续获取 12 个图像,并且还想使用“i array”简化代码的“if”和“else if”部分

else if (img.length >=8) imgtag = '<a class="featured_gallery" href="' + img[0].src + '"><img src="' + img[0].src + '" /></a><a class="featured_gallery" href="' + img[1].src + '"><img src="' + img[1].src + '" /></a><a class="featured_gallery" href="' + img[2].src + '"><img src="' + img[2].src + '" /></a><a class="featured_gallery" href="' + img[3].src + '"><img src="' + img[3].src + '" /></a><a class="featured_gallery" href="' + img[4].src + '"><img src="' + img[4].src + '" /></a><a class="featured_gallery" href="' + img[5].src + '"><img src="' + img[5].src + '" /></a><a class="featured_gallery" href="' + img[6].src + '"><img src="' + img[6].src + '" /></a><a class="featured_gallery" href="' + img[7].src + '"><img src="' + img[7].src + '" /></a>';

任何精通 javascript 的人都可以帮助我解决这个问题吗?

我希望仅在 JavaScript 中实现

最佳答案

您的代码存在一些逻辑错误,如果您使用迭代语句,请更改

imgtag+='<a href="' + y + '"><img src="' + img[i].src + '" style="max-width:100%;" alt="' + x + '" /></a>'

关于javascript - 如何使用javascript连续追加12张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25303739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com