现在的位置: 首页 > 综合 > 正文

用js进行htmlencode与decode

2019年08月10日 ⁄ 综合 ⁄ 共 249字 ⁄ 字号 评论关闭

function HtmlEncode(text)
{
return text.replace(/&/g, '&amp').replace(//"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

function HtmlDecode(text)
{
return text.replace(/&amp;/g, '&').replace(/&quot;/g, '/"').replace(/&lt;/g, '<').replace(/&gt;/g, '>');
}

【上篇】
【下篇】

抱歉!评论已关闭.