【备忘】cnblogs 插 HTML demo

使用 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 声明标签

 

posted @ 2012-12-12 17:38  ecalf  阅读(389)  评论(0编辑  收藏  举报