JS转义html


原生写法

function htmlDecode(input){
  var e = document.createElement('div');
  e.innerHTML = input;
  return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
htmlDecode("<img src='myimage.jpg'>"); 

jquery写法

function htmlDecode(value){ 
  return $('<div/>').html(value).text(); 
}

参考链接


出来混~总是要还的 ~

猜你喜欢

转载自blog.csdn.net/seven_north/article/details/87872407