美文网首页
Convert HTML Entities

Convert HTML Entities

作者: yyggfffg | 来源:发表于2018-05-04 16:22 被阅读0次

将字符串中的字符 &、<、>、" (双引号), 以及 ' (单引号)转换为它们对应的 HTML 实体。

function convert(str) {
  // &colon;&rpar;
  str=str.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;");
  return str;
}

convert("Dolce & Gabbana");

相关文章

网友评论

      本文标题:Convert HTML Entities

      本文链接:https://www.haomeiwen.com/subject/fxodrftx.html