Home > Web Front-end > HTML Tutorial > html decode 方法_html/css_WEB-ITnose

html decode 方法_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:42:23
Original
1298 people have browsed it

当使用document.querySelector('

') 获取元素时,发现html里某些特殊字符被处理和转意了,处理后格式如下:

<

>

&

''

  ………………

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;
Copy after login

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

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template