【备忘】cnblogs 插 HTML demo

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

<p>
<textarea id="ecalfCodes" style="margin: 2px;  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 声明标签
原文地址:https://www.cnblogs.com/ecalf/p/2815066.html