您现在的位置是:首页 > 电脑技术查询 > web开发

有没有方法给html进行编码?解决方法

编辑:chaxungu时间:2022-10-02 23:20:25分类:web开发

有没有方法给html进行编码?
例如把 " < "、 "> "等字符编码成&lt、&gt这种格式?

------解决方案--------------------
String.prototype.replaceStr=function(){return this.replace(/&/g, "&amp; ").replace(/\ "/g, "&quot; ").replace(/ </g, "&lt; ").replace(/> /g, "&gt; ");}