js如何循环替换代码添加代码
<divclass="nrnr"id="wznr"><ahref='1405_3.html'><imgalt=""src="/uploads/caiji/2011/03/...
<div class="nrnr" id="wznr">
<a href='1405_3.html'><img alt="" src="/uploads/caiji/2011/03/27/cj-14587.jpg" /></a><br />
<a href='1405_3.html'><img alt="" src="/uploads/caiji/2011/03/27/cj-14588.jpg" /></a><br />
</div>
<SCRIPT language="javascript">
window.onload=function()
{
var obj = document.getElementById("wznr");
var imgs = obj.getElementsByTagName("img");
var imgurl = new Array(imgs.length);
for(var i=0;i<imgs.length;i++)
{
imgurl[i]=imgs[i].src;
var yzi="></a>";
obj.innerHTML=obj.innerHTML.replace(yzi,"></a><br /><a href=# target=_blank>↑↑点击查看原图</a>");
}
}
</SCRIPT>
如上代码,我要在上面的图片下面加上个超链接,这个超链接的地址是上面的图片地址。
大概如下的效果:
<a href='1405_3.html'><img alt="" src="/uploads/caiji/2011/03/27/cj-14587.jpg" /></a><a href=/uploads/caiji/2011/03/27/cj-14587.jpg >原图</a>
<a href='1405_3.html'><img alt="" src="/uploads/caiji/2011/03/27/cj-14588.jpg" /></a><a href=/uploads/caiji/2011/03/27/cj-14588.jpg >原图< 展开
<a href='1405_3.html'><img alt="" src="/uploads/caiji/2011/03/27/cj-14587.jpg" /></a><br />
<a href='1405_3.html'><img alt="" src="/uploads/caiji/2011/03/27/cj-14588.jpg" /></a><br />
</div>
<SCRIPT language="javascript">
window.onload=function()
{
var obj = document.getElementById("wznr");
var imgs = obj.getElementsByTagName("img");
var imgurl = new Array(imgs.length);
for(var i=0;i<imgs.length;i++)
{
imgurl[i]=imgs[i].src;
var yzi="></a>";
obj.innerHTML=obj.innerHTML.replace(yzi,"></a><br /><a href=# target=_blank>↑↑点击查看原图</a>");
}
}
</SCRIPT>
如上代码,我要在上面的图片下面加上个超链接,这个超链接的地址是上面的图片地址。
大概如下的效果:
<a href='1405_3.html'><img alt="" src="/uploads/caiji/2011/03/27/cj-14587.jpg" /></a><a href=/uploads/caiji/2011/03/27/cj-14587.jpg >原图</a>
<a href='1405_3.html'><img alt="" src="/uploads/caiji/2011/03/27/cj-14588.jpg" /></a><a href=/uploads/caiji/2011/03/27/cj-14588.jpg >原图< 展开
展开全部
<SCRIPT language="javascript">
window.onload = function () {
var obj = document.getElementById("wznr");
var imgs = obj.getElementsByTagName("img");
var imgurl = new Array(imgs.length);
for (var i = 0; i < imgs.length; i++) {
imgurl[i] = imgs[i].src;
var link = "<br /><a href=" + imgurl[i] + " target=_blank>↑↑点击查看原图</a>";
imgs[i].parentNode.outerHTML = imgs[i].parentNode.outerHTML + link;
}
}
</SCRIPT>
window.onload = function () {
var obj = document.getElementById("wznr");
var imgs = obj.getElementsByTagName("img");
var imgurl = new Array(imgs.length);
for (var i = 0; i < imgs.length; i++) {
imgurl[i] = imgs[i].src;
var link = "<br /><a href=" + imgurl[i] + " target=_blank>↑↑点击查看原图</a>";
imgs[i].parentNode.outerHTML = imgs[i].parentNode.outerHTML + link;
}
}
</SCRIPT>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询