使用javascript替换特定的html标签 [英] Replace particular html tags using javascript
本文介绍了使用javascript替换特定的html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用#
&替换每个< li>
标记每个</li>
与< br/>
I want to replace every <li>
tag with #
& every </li>
with <br />
我认为我需要一个全局替换函数,而不是简单的 string.replace()
这样...
I think I need a global replace function for that rather than a simple string.replace()
so...
var s=obj1.innerHTML;
s = s.replace(/<li>/g,"# ");
s = s.replace(/</li>/g,"<br/>");
但是它似乎没有用.有什么错误吗?
But it doesn't seem to be working. Any mistake ?
编辑:我将在Blogger&这就是为什么需要对其进行解析的原因.这就是为什么您看到&"
而不是"
的原因.
I am going to use the code in blogger & that is why it needs to be parsed.So that's why you see "
instead of "
.
推荐答案
这样做:-
LIVE DEMO
var s="<div>hello world <br/><li>First LI</li><li>Second LI</li></div>";
s = s.replace(/<li>/g, "#");
s = s.replace(/<\/li>/g,"<br/>");
alert(s);
这篇关于使用javascript替换特定的html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文