Home  >  Article  >  Web Front-end  >  JS保存、读取、换行、转Json报错处理方法_javascript技巧

JS保存、读取、换行、转Json报错处理方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:32:131225browse

异常信息:Unexpected token ILLEGAL

先说处理方法:
1.保存:

复制代码 代码如下:

varcont=encodeURI($("#txtMessage_Content").val()).replace(/%0A/g,"brHH");

2.读取:
复制代码 代码如下:

entity[i].Contents.replace(/,"/,">").replace(/brHH/g,"
")

说明:
主要思路是替换法。
js直接抓文本貌似无法抓到 回车,encodeURI一下就可以抓到了%0A
复制代码 代码如下:

replace(/,"/,">")

这句是处理JS注入的
复制代码 代码如下:

replace(/brHH/g,"
")

这里是把上面替换回车的再替换回来显示
Statement:
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