itheima-toooools
Version:
提供了格式化时间,htmlescape相关的功能
35 lines (34 loc) • 694 B
JavaScript
// 定义转义HTML 字符的函数
function htmlescape(htmlstr) {
return htmlstr.replace(/<|>|"|&/g, match => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 还原html标签的函数
function htmlUnEscape(str) {
return str.replace(/<|>|"|&/g, (match) => {
switch (match) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
module.exports={
htmlescape,
htmlUnEscape
}