asp下实现代码的“运行代码”“复制代码”“保存代码”功能源码

来源:asp之家 时间:2011-04-14 10:39:00 

Function content_Code(Str) 
dim ary_String,i,n,n_pos 
ary_String=split(Str,"[ code ]") 
n=ubound(ary_String) 
If n<1 then 
content_Code=Str 
Exit function 
End If 
for i=1 to n 
n_pos=inStr(ary_String(i),"[/ code ]") 
If n_pos>0 then 
ary_String(i)="<br /><textarea class=gocode id=runcode"&i&" name=runcode"&i&">" & server.HTMLEncode(left(ary_String(i),n_pos-1))&"</textarea><br /><input type=button class=input-code value=运行代码 onclick=runCode(runcode"&i&")><input type=button class=input-code value=复制代码 onclick=copycode(runcode"&i&")><input type=button class=input-code value=另存代码 onclick=saveCode(runcode"&i&")><span class=code-tishi>提示:您可以先修改部分代码再运行</span><br />" & _ 
right(ary_String(i),len(ary_String(i))-n_pos-6) 
Else 
ary_String(i)="[code]" & ary_String(i) 
End if 
next 
content_Code=join(ary_String,"") 
End Function 
使用方法也很简单:
发表文章时需用使用“运行代码”功能的,主要前后加上

[ code ][/ code ] 
比如:
[复制此代码]CODE:

[ code ] 
<script type="text/javascript"> 
alert("简单吧"); 
</script> 
[/ code ] 
需要注意的是,在显示的页面要进入以下javascript:

function runCode(obj) { 
var winname = window.open('', "_blank", ''); 
winname.document.open('text/html', 'replace'); 
winname.opener = null 
winname.document.writeln(obj.value); 
winname.document.close(); 

function copycode(obj) { 
var rng = document.body.createTextRange(); 
rng.moveToElementText(obj); 
rng.scrollIntoView(); 
rng.select(); 
rng.execCommand("Copy"); 
rng.collapse(false); 

function saveCode(obj) { 
var winname = window.open('', '_blank', 'top=10000'); 
winname.document.open('text/html', 'replace'); 
winname.document.write(obj.value); 
winname.document.execCommand('saveas','','code.htm'); 
winname.close(); 
}

标签:asp,运行代码,复制代码
0
投稿

猜你喜欢

  • Asp 单页查询数据库

    2010-05-11 20:11:00
  • seo网站如何实现301跳转?

    2010-01-15 12:59:00
  • 讲解SQL Server2005数据项的分拆与合并

    2009-01-04 14:40:00
  • HTML5本地存储初探(三)

    2010-03-07 15:49:00
  • 如何固定表格的标题行和标题列

    2007-09-20 13:03:00
  • Select的OnChange()事件

    2009-03-03 12:40:00
  • 网页推广设计的几个要点

    2011-01-10 20:41:00
  • SQL查询入门(中篇)

    2011-09-30 11:15:09
  • 交互设计实用指南系列(11)—减少记忆负担

    2010-03-29 13:12:00
  • Mysql日期和时间函数大全

    2011-03-08 09:52:00
  • 教你如何在SQL Server数据库中加密数据

    2009-09-10 14:49:00
  • ASP实例:即时显示当前页面浏览人数

    2008-04-19 22:02:00
  • ASP中使用Set ors=oConn.Execute()时获取记录数的方法

    2011-02-20 10:48:00
  • T-SQL问题解决集锦 数据加解密全集

    2012-07-11 15:34:08
  • asp OpenTextFile文本读取与写入实例代码

    2011-04-15 11:00:00
  • SQL学习笔记八 索引,表连接,子查询,ROW_NUMBER

    2011-09-30 11:18:24
  • 详解CSS3中的属性选择符

    2008-04-24 14:30:00
  • Windows 2003服务器上传文件受限制的解决方法

    2011-02-14 11:29:00
  • CSS Hack 汇总快查

    2007-11-06 11:48:00
  • JS代码的格式化和压缩

    2007-10-17 21:17:00
  • asp之家 网络编程 m.aspxhome.com