Skip to content

Instantly share code, notes, and snippets.

@codeachange
Created November 15, 2015 11:54
Show Gist options
  • Save codeachange/f7225051c57271cd051a to your computer and use it in GitHub Desktop.
Save codeachange/f7225051c57271cd051a to your computer and use it in GitHub Desktop.
微信公众号文章页面的 javascript encode/decode html
String.prototype.html = function(encode) {
var replace =["&#39;", "'", "&quot;", '"', "&nbsp;", " ", "&gt;", ">", "&lt;", "<", "&amp;", "&", "&yen;", "¥"];
if (encode) {
replace.reverse();
}
for (var i=0,str=this;i< replace.length;i+= 2) {
str=str.replace(new RegExp(replace[i],'g'),replace[i+1]);
}
return str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment