📎 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());

posted on 2019-07-19 14:32  小蜜蜂是会飞的  阅读(401)  评论(0编辑  收藏  举报

导航