我们在写博文时需要添加一段代码,为让读者能即时看到代码效果,我们需加上其他代码可以有运行代码,复制代码,另存代码的效果。
演示:
<div>欢迎订阅李明博客:<a href="https://www.blogs.hk" kesrc="https://www.blogs.hk">https://www.blogs.hk</a></div>
代码在线操作代码:
<p class="MsoNormal"><textarea style="width:679px;height:94px;" cols="50" rows="15" name="code" class="c-sharp">
<style>
.button { border:1px solid #b1b4cd; background:#696d81; color:#ffffff; height:25px; line-height:25px; }
</style>
<script language="javascript">
function runCode(obj){
var bb=window.open('', "_blank", '');
bb.document.open('text/html', 'replace');
bb.opener = null; // 防止代码对页面修改
var obj=document.getElementById(obj);
bb.document.write(obj.value);
bb.document.close();
}
function copycode(obj) {
var obj=document.getElementById(obj);
obj.select();
document.execCommand("copy");
}
function saveCode(obj) {
var obj=document.getElementById(obj);
document.write(obj.value);
document.close();
document.execCommand("saveAs",0,"nuodou_com_test.htm");
}
</script>
<textarea id="code" cols=80 rows=15>加上你的代码</textarea>
<br /><br />
<input type="button" onclick='javascript:runCode("code")' value="运行代码" class="button">
<input type="button" onclick='javascript:copycode("code")' value="复制代码" class="button">
<input type="button" onclick='javascript:saveCode("code")' value="另存代码" class="button">
<br /><br />
</textarea> </p>
文章作者:博客之家
文章標題:代码在线操作代码分享
文章鏈接:https://www.blogs.hk/80.html
本站所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議,轉載請註明來自博客之家 !
文章標題:代码在线操作代码分享
文章鏈接:https://www.blogs.hk/80.html
本站所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議,轉載請註明來自博客之家 !

评论列表(12条)