Skip to content

Instantly share code, notes, and snippets.

@simplelife7
Created July 9, 2013 01:59
Show Gist options
  • Save simplelife7/5954079 to your computer and use it in GitHub Desktop.
Save simplelife7/5954079 to your computer and use it in GitHub Desktop.
【JS】HTML转义
function htmlEncode(str) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(str));
return div.innerHTML;
}
function htmlDecode(str) {
var div = document.createElement("div");
div.innerHTML = str;
return div.innerHTML;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment