function htmlEscape(str) {
return String(str)
.replace(/&/g, ‘&‘)
.replace(/"/g, ‘"‘)
.replace(/‘/g, ‘'‘)
.replace(/</g, ‘<‘)
.replace(/>/g, ‘>‘);
}
var path = ‘<div>hello world</div><p> </p>‘;
var res = htmlEscape(path);
console.log(res);
时间: 2024-11-11 06:52:02