首页 > 代码库 > 9. js实现java方法:HtmlUtils.htmlEscape()

9. js实现java方法:HtmlUtils.htmlEscape()

function htmlEscape(str) {
return String(str)
.replace(/&/g, ‘&‘)
.replace(/"/g, ‘"‘)
.replace(/‘/g, ‘'‘)
.replace(/</g, ‘&lt;‘)
.replace(/>/g, ‘&gt;‘);
}
var path = ‘<div>hello world</div><p>&nbsp;</p>‘;
var res = htmlEscape(path);
console.log(res);

9. js实现java方法:HtmlUtils.htmlEscape()