Created
August 25, 2014 13:47
-
-
Save hacke2/d02e5c607a2a2382a6bd 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 htmlEscape(text) { | |
return text.replace(/[<>"&]/g, function(match, pos, originalText){ | |
switch(match) { | |
case "<" : return "<"; | |
case ">" : return ">"; | |
case "\"" : return "&"; | |
case "&" : return """; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment