从字符串中删除无效的html标记 [英] Remove invalid html tags from a string

查看:88
本文介绍了从字符串中删除无效的html标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:< div>是否有任何方式使用javascript从字符串中移除无效的HTML标记? < FOO>< /富> < / code>应转换为< div>< / div>

h2_lin>解决方案

看起来你正试图推出自己的HTML清理器。我不会推荐。相反,请查看其他已经要求使用清洁剂的问题:清理/重写HTML在客户端



具体来说,这里有一个可供使用的地方: https://code.google.com/p/google-caja/wiki/JsHtmlSanitizer


Is there any way with javascript to remove invalid HTML tags from a string?

Ex: <div> <foo></foo> </div> should be transformed to <div></div>

解决方案

It looks like you're trying to roll your own form of HTML sanitizer. I would not recommend that. Instead, check out other questions that have already asked for a sanitizer: Sanitize/Rewrite HTML on the Client Side

Specifically, there's one available for use here: https://code.google.com/p/google-caja/wiki/JsHtmlSanitizer

这篇关于从字符串中删除无效的html标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆