itheima-zwhy
Version:
提供了格式化时间日期,转换特殊字符,yyds
35 lines (34 loc) • 815 B
JavaScript
// 定义转换HTML字符函数
function changeStr(htmlStr) {
return htmlStr.replace(/<|>|"|&/g, (str) => {
switch (str) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
// 定义还原HTML字符函数
function deacidizing(abc) {
return abc.replace(/<|>|"|&/g, (str1) => {
switch (str1) {
case '<':
return '<'
case '>':
return'>'
case '" ':
return '"'
case '&':
return '&'
}
})
}
module.exports = {
changeStr,
deacidizing
}