参考 http://stackoverflow.com/questions/6020714/escape-html-using-jquery

1 escapeHTML = function(text) {
2   return $('<div/>').text(text).html();
3 }
4 
5 escapeHTML('<div id="main">');
6 // "&lt;div id="main"&gt;"