【发布时间】:2014-12-28 19:15:58
【问题描述】:
我尝试了 MS Word 中的 VBA 宏(我目前使用的 PC 没有太多东西),结果不是很好,所以我用 Firefox 控制台尝试了它。
这是我当前的代码:
function stripAnchorTags(html) {
return html.replace(/\<a.*\>.*\<\/a\>/, '');
}
console.log(stripAnchorTags('<a href="image location" style="margin-left: 1em; margin-right: 1em;"><img src="image location" border="0" height="400" width="640"></a></div><br><a href="image location" style="margin-left: 1em; margin-right: 1em;"><img src="image location" border="0" height="400" width="640"></a></div>'));
现在,我想要的输出是
<img src="image location" border="0" height="400" width="640"></div><br><img src="image location" border="0" height="400" width="640"></div>
但不是它,我只得到</div>
我不知道出了什么问题。
【问题讨论】:
-
不要使用正则表达式解析 HTLM。 stackoverflow.com/questions/1732348/…
-
如果您向我们提供有关您想要做什么的一些见解,也许我们可以帮助您以更好的方式来做这件事。用 jQuery 应该很简单,但是你用的是 jQuery 吗?
标签: javascript