jibamao-lxf
Version:
提供了格式化时间、htmlEscape、htmlUnescape三个函数
36 lines (34 loc) • 771 B
JavaScript
// 封装转化标签特殊字符的函数
function htmlEscape(str) {
return str.replace(/>|<|"|&/g, function (match) {
switch (match) {
case '>':
return '>';
case '<':
return '<';
case '"':
return '"';
case '&':
return '&';
}
});
}
// 封装函数将包含特定实体字符的字符串还原成标签字符串
function htmlUnescape(str) {
return str.replace(/>|<|"|&/g, function (match) {
switch (match) {
case '>':
return '>';
case '<':
return '<';
case '"':
return '"';
case '&':
return '&';
}
});
}
module.exports = {
htmlEscape,
htmlUnescape
}