【发布时间】:2012-05-18 17:54:47
【问题描述】:
我用一个例子来说明:我需要用javascript转换下面的html
<a>Text 1</a>
<a>Text 2</a>
<a>Text 3</a>
...
编码
<a><input/>Text 1</a>
<a><input/>Text 2</a>
<a><input/>Text 3</a>
...
我不知道如何使用 createElement、appendChild 或 insertBefore/After 来实现。
【问题讨论】:
-
你可以选择 jQuery 吗?这实际上也不是有效的html在href中的输入..
-
把它当作一个字符串。获取 HTML,使用 .replace(),将其插入回去。
标签: javascript html dom appendchild