itheima-tools-babamama
Version:
提供了格式化时间,两只老虎
37 lines (35 loc) • 845 B
JavaScript
// 定义转义HTML字符的函数
function htmlEscaped(data){
return data.replace(/<|>|"|&/g,(match) =>{
switch(match){
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 定义还原 HTML 字符串的函数
function htmlUnEscaped(str) {
return str.replace(/<|>|"|&/g,(match) =>{
switch(match){
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
}
)
}
module.exports = {
htmlEscaped,
htmlUnEscaped
}