luck-tools
Version:
提供了格式时间,转义HTML中的特殊字符
34 lines • 808 B
JavaScript
//定义HTML转义的函数
function htmlescape(htmlstr){
return htmlstr.replace(/<|>|"|&/g,math=>{
switch (math) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
//定义还原HTML的函数
function hyhtml(htmlstr){
return htmlstr.replace(/<|>|"|&/g,math=>{
switch (math) {
case '<':
return '<'
case '>':
return '>'
case '"':
return '"'
case '&':
return '&'
}
})
}
module.exports = {
htmlescape,
hyhtml
}