js
富文本反转义html
function escape2Html(str){
var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) {
return arrEntities[t];
});
}
富文本转义html
function html2Escape(str){
return sHtml.replace(/[<>&"]/g, function (c) {
return { '<': '<', '>': '>', '&': '&', '"': '"' }[c];
});
}
vue
富文本反转义html
export const escape2Html = (str) => {
var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) {
return arrEntities[t];
});
}
富文本转义html
export const html2Escape = (str) => {
return sHtml.replace(/[<>&"]/g, function (c) {
return { '<': '<', '>': '>', '&': '&', '"': '"' }[c];
});
}