Created
November 16, 2012 08:44
-
-
Save vivisidea/4085559 to your computer and use it in GitHub Desktop.
转换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(s){ | |
var el = document.createElement("div"); | |
el.innerText = el.textContent = s; | |
s = el.innerHTML; | |
return s; | |
} | |
// Test run: | |
// alert(HtmlEncode('&;\'><"')); | |
// jquery: $('<div>').text(value.word).html() | |
// reference: http://stackoverflow.com/questions/784586/convert-special-characters-to-html-in-javascript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment