javascript 实现htmlEncode htmlDecode

时间:2022-11-22 06:15:52

屌屌的写法。。 function htmlEncode(value){
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
return $('<div/>').text(value).html();
} function htmlDecode(value){
return $('<div/>').html(value).text();
}