Created
July 9, 2013 01:59
-
-
Save simplelife7/5954079 to your computer and use it in GitHub Desktop.
【JS】HTML转义
This file contains 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
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