"); s = s.replace(/<"); s = s.replace(/>/g, ">"); s = s.replace(/_js对html转义">
当前位置:   article > 正文

html 转义js_js对html转义

js对html转义

  1. function html_encode(str)
  2. {
  3. var s = "";
  4. if (str.length == 0) return "";
  5. s = str.replace(/&/g, ">");
  6. s = s.replace(/</g, "<");
  7. s = s.replace(/>/g, ">");
  8. s = s.replace(/ /g, " ");
  9. s = s.replace(/\'/g, "'");
  10. s = s.replace(/\"/g, """);
  11. s = s.replace(/\n/g, "<br>");
  12. return s;
  13. }
  14. function html_decode(str)
  15. {
  16. var s = "";
  17. if (str.length == 0) return "";
  18. s = str.replace(/>/g, "&");
  19. s = s.replace(/</g, "<");
  20. s = s.replace(/>/g, ">");
  21. s = s.replace(/ /g, " ");
  22. s = s.replace(/'/g, "\'");
  23. s = s.replace(/"/g, "\"");
  24. s = s.replace(/<br>/g, "\n");
  25. return s;
  26. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/131102
推荐阅读