本机JavaScript或ES6编码和解码HTML实体的方式? [英] Native JavaScript or ES6 way to encode and decode HTML entities?

查看:188
本文介绍了本机JavaScript或ES6编码和解码HTML实体的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在使用JavaScript或 HTML实体进行编码或解码的本地方法ES6?例如,<将被编码为&lt;.有一些像Node.js的库 html-entities ,但感觉应该有一些东西内置在已经可以满足这种常见需求的JavaScript中.

解决方案

JavaScript API中没有本机函数可将ASCII字符转换为等效的"html-entities". 这是开始的解决方法HTML entities using JavaScript or ES6? For example, < would be encoded as &lt;. There are libraries like html-entities for Node.js but it feels like there should be something built into JavaScript that already handles this common need.

解决方案

There is no native function in the JavaScript API that convert ASCII characters to their "html-entities" equivalent. Here is a beginning of a solution and an easy trick that you may like

这篇关于本机JavaScript或ES6编码和解码HTML实体的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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