String.prototype.toHtmlEncode = function() { var str = this; str=str.replace("&","&"); str=str.replace("<","<"); str=str.replace(">",">"); str=str.replace("'","'"); str=str.replace(""","""); return str; }
用法
"".toHtmlEncode()