- 출처: http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery -
javascript replace() 함수의 두 번째 인수로 함수를 넣을 수 있다는 것을 처음 알았다. ^ㅁ^;
var entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
"'": ''',
"/": '/'
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}