使用 HTML 源码编辑模式,贴近下面代码

<p>
<textarea id="ecalfCodes" style="margin: 2px; width: 703px; height: 415px;" rows="8" cols="80"> 

//这里是转换尖括号之后的DEMO源代码
 
</textarea>
</p>
<p><input onclick="runCode('ecalfCodes')" type="button" value="运行代码" /></p>

<script type="text/javascript">// <![CDATA[
function runCode(id){
var obj=document.getElementById(id);
var win = window.open('', "_blank", '');
win.document.open('text/html', 'replace');
win.opener = null;
win.document.write(obj.value);
win.document.close();
}
// ]]></script>

然后 将 demo 页面的源代码中的尖括号转换成 实体符。

document.documentElement.innerHTML.replace(/\<|\>/g,function(s){ return '&#'+s.charCodeAt(0)+';'; })

//得到的字符串没有 <HTML>和DOCTYPE 声明标签

 

相关文章:

  • 2021-09-05
  • 2021-08-19
  • 2021-07-05
  • 2021-11-19
  • 2021-06-11
  • 2021-07-28
  • 2022-01-27
  • 2022-12-23
猜你喜欢
  • 2021-08-04
  • 2021-05-25
  • 2021-07-12
  • 2022-01-20
  • 2021-06-13
  • 2021-11-10
  • 2022-12-23
相关资源
相似解决方案