如何用Imgae替换[Img] [/ Img]标签

编程入门 行业动态 更新时间:2024-10-27 11:16:32
本文介绍了如何用Imgae替换[Img] [/ Img]标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果有人使用 [img] [/ img] 标记对Blogger发表评论,则会发布此HTML代码。假设代码类似

< div id = mm > [img] www.gravatar/avatar/4ce47f47105a3bd1ca4700f02b5deff1?s=32&d=identicon&r=PG [ / img] < / div >

我们的javascript应找到[img]标签并将其替换为图像。所以javascript可能是这样的:

var s; s = document .getElementById( mm )。innerHTML s = s.replace( [img], '); s = s.replace( [/ img], '); var b; b = < img src = + s + >< / img> document .getElementById ( mm)。innerHTML = b;

当div id =mm仅包含[img] [/ img]标签时,它可以工作。但是当它们是其他文本或代码时,它就无法显示e图像。请帮我。在此先感谢

解决方案

您要将 [img] [/ img] 结构的内容放入

< img src = 在JS执行后,您捕获的内容将在此处输入 > < / img >

如果 [img] [/ img] 的内容没有生成有效的src属性,显然它不会显示预期的图像。 干杯。 C

我修改了demo的代码,下面的代码按预期工作: (用于验证我已经为url设置了警报,你可以删除它)

< div id =mm>一些废话文本[img] www.gravatar/avatar/ 4ce47f47105a3bd1ca4700f02b5deff1?s = 32& d = identicon& r = PG [/ img]一些废话文本< / div> < script> var s; s = document.getElementById(mm)。innerHTML var afterImg = s.split([img])[1]; var url = afterImg.split([/ img])[0]; alert(url); var b =< img src =+ url +>< / img> document.getElementById(mm)。innerHTML = b; < / script>

如果有任何进一步的问题,请与我们联系。感谢。

When someone comment on Blogger with [img][/img] tag then this HTML code is published. Assume the code like that

<div id="mm">[img]www.gravatar/avatar/4ce47f47105a3bd1ca4700f02b5deff1?s=32&d=identicon&r=PG[/img]</div>

Our javascript should find the [img] tag and replace that with an image. So javascript may be like this:

var s; s = document.getElementById("mm").innerHTML s = s.replace("[img]","'"); s = s.replace("[/img]","'"); var b; b = "<img src="+s+"></img>" document.getElementById("mm").innerHTML = b;

it works when the div id="mm" contains only [img] [/img] tag. but when their is other text or code then it fails to thdisplay e image. Please help me. Thanks in advance

解决方案

You are placing the content of the [img][/img] structure into the

<img src="Your captured content enters here after the JS execution"></img>

If the content of the [img][/img] does not make a valid src property, obviously it will not show the intended image. Cheers. C

I have modified the code for demo and below code is working as expected: (for verification I have put alert for url, you can remove that)

<div id="mm">Some Crap Text[img]www.gravatar/avatar/4ce47f47105a3bd1ca4700f02b5deff1?s=32&d=identicon&r=PG[/img]Some Crap Text </div> <script> var s; s = document.getElementById("mm").innerHTML var afterImg = s.split("[img]")[1]; var url = afterImg.split("[/img]")[0]; alert(url); var b = "<img src=" + url + "></img>" document.getElementById("mm").innerHTML = b; </script>

Please let me know if any further issue. Thanks.

更多推荐

如何用Imgae替换[Img] [/ Img]标签

本文发布于:2023-10-29 20:28:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540659.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何用   标签   Imgae   Img

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!