网站存储空间,邯郸网站设计培训,百度搜索引擎收录,如何上传安装网站模板注意#xff1a;
在编写html时#xff0c;经常需要转义#xff0c;才能正常显示在页面上。
并且#xff0c;还可以防止xss。
解决方案#xff1a;
一#xff0c; 使用正则#xff1a;
使用正则转码#xff1a; var value document.getElementById(input).value.t…注意
在编写html时经常需要转义才能正常显示在页面上。
并且还可以防止xss。
解决方案
一 使用正则
使用正则转码 var value document.getElementById(input).value.trim();//对用户输入进行转义value value.replace(//g,amp;);value value.replace(//g,lt;);value value.replace(//g,gt;);value value.replace(/ /g,nbsp;);value value.replace(//g,quot;); 使用正则解码 var value e.target.innerText;// value decodeURIComponent(value);value value.replace(/amp;/g,);value value.replace(/lt;/g,);value value.replace(/gt;/g,);value value.replace(/nbsp;/g, );value value.replace(/quot/g,); 方法二使用浏览器自带的。详情异步https://www.cnblogs.com/GumpYan/p/7883133.html
更多专业前端知识请上
【猿2048】www.mk2048.com