huang-tools
Version:
提供格式化日期时间,转换及还原标签的功能
35 lines (34 loc) • 765 B
JavaScript
// 定义转换为html字符串函数
function htmlEscape(htmlStr) {
return htmlStr.replace(/>|<|"|&/g, function (match) {
switch (match) {
case '>':
return '>';
case '<':
return '<';
case '"':
return '"';
case '&':
return '&';
}
});
}
// 定义将包含实体字符的字符串还原成html字符串的函数
function htmlUnescape(str) {
return str.replace(/>|<|"|&/g, function (match) {
switch (match) {
case '>':
return '>';
case '<':
return '<';
case '"':
return '"';
case '&':
return '&';
}
});
}
module.exports = {
htmlEscape,
htmlUnescape
};