[英]encode accented characters into html entities using javascript
I would like to convert this text éàè
to éàè
我想将此文本
éàè
转换为éàè
using javascript. 使用javascript。
I tried $('<textarea />').text("éàe").html();
我尝试了
$('<textarea />').text("éàe").html();
but it doesn't encode the accented characters... 但它不对重音字符进行编码...
The org.apache.commons.lang3.StringEscapeUtils.escapeHtml
works correctly in Java, is there an equivalent for javascript ? org.apache.commons.lang3.StringEscapeUtils.escapeHtml
在Java中可以正常运行,javascript是否具有等效功能?
If you use ES6, you might be interested in tagged template literals ... 如果使用ES6,您可能会对标记的模板文字感兴趣...
function htmlentities(raw) { const str = raw[0]; return str.replace(/é/g, 'é') .replace(/à/g, 'à') .replace(/è/g, 'è'); } console.log(htmlentities`éàè`);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.