Created
November 15, 2015 11:54
-
-
Save codeachange/f7225051c57271cd051a to your computer and use it in GitHub Desktop.
微信公众号文章页面的 javascript encode/decode html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.html = function(encode) { | |
var replace =["'", "'", """, '"', " ", " ", ">", ">", "<", "<", "&", "&", "¥", "¥"]; | |
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