如果有人使用 [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]标签
发布评论