cn.edu.wust.qrz-nodejs-tools
Version:
提供格式化时间,HTMLEscape的功能
37 lines (35 loc) • 873 B
JavaScript
//定义转义html字符函数
function htmlEscape(htmlstr) {
return htmlstr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
//定义函数--将转义字符还原为html标签
function htmlUnEscape(htmlstr) {
return htmlstr.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
//导出
module.exports = {
htmlEscape,
htmlUnEscape
}