📎 Emoji 前端转换

var unicodeTrans = (function () {
function UnicodeTrans() {}
UnicodeTrans.prototype.deUnicode = function (str) {
var strArray = str.split("\u");
if (str.startsWith("\u")) {
strArray = strArray.slice(1, strArray.length);
}
if (str.endsWith("\u")) {
strArray = strArray.slice(0, strArray.length - 1);
}
var res = "";
for (var i = 0; i < strArray.length; i++) {
var getCharCode = parseInt(strArray[i], 16);
var getCharCodeStr = String.fromCharCode(getCharCode);
// IF lineFeed
if (getCharCode == 10) {
getCharCodeStr = '<br/>';
}
// IF blankSpace
if (getCharCode == 32) {
getCharCodeStr = '&nbsp;';
}
res += getCharCodeStr;
}
return res;
}
return new UnicodeTrans();
}());

 var origin = unicodeTrans.deUnicode($(ele).text());

原文地址:https://www.cnblogs.com/little-bee-fly/p/11213096.html