当使用document.querySelector('<div>') 获取元素时,发现html里某些特殊字符被处理和转意了,处理后格式如下:

&lt;

&gt;

&amp;

'&#039;

  ………………

PS: 当我不熟悉正则的时候,想偷懒的时候,就借用HTMLDivElement object获取内容,竟然发现!!!尼玛全是“乱码”……

怎么办?

方法1:

写个html decode 方法,然后各种转换……

ps: 真心尼玛不靠谱啊! 有哪些特殊字符会被html处理掉,我都没搞太明白!

方法2:

var _textarea = document.createElement('textarea');

_textarea.innerHTML =document.querySelector('#htmlCodeId').innerHTML;

console.log( _textarea .value );




// 用完后,强烈建议_textarea置空
_textarea = null;

ps: 多、快、好、省  /^-^\

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2021-09-25
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2023-03-12
  • 2021-12-02
相关资源
相似解决方案