/g, "&._html 字符编码函数">
赞
踩
- //html编码,字符串转为实体
- function htmlEncodeByRegExp(str) {
- var temp = "";
- if (str.length == 0) return "";
- temp = str.replace(/&/g, "&");
- temp = temp.replace(/</g, "<");
- temp = temp.replace(/>/g, ">");
- temp = temp.replace(/\s/g, " ");
- temp = temp.replace(/\'/g, "'");
- temp = temp.replace(/\"/g, """);
- return temp;
- }
- //html实体解码,实体转为字符串。
- function htmlDecodeByRegExp(str) {
- var temp = "";
- if (str.length == 0) return "";
- temp = str.replace(/&/g, "&");
- temp = temp.replace(/</g, "<");
- temp = temp.replace(/>/g, ">");
- temp = temp.replace(/ /g, " ");
- temp = temp.replace(/'/g, "\'");
- temp = temp.replace(/"/g, "\"");
- return temp;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。