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

所属分类: 网络编程 / ASP编程 阅读数: 208
收藏 0 赞 0 分享
看到很多人需要,就放出来,好东西大家一起分享。 
复制代码 代码如下:

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 ] 
<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中去除内容HTML标签的三个function函数

asp中去除内容HTML标签的三个function函数
收藏 0 赞 0 分享

chr(9)、chr(10)、chr(13)、chr(32)、chr(34)讲解

chr(9)、chr(10)、chr(13)、chr(32)、chr(34)讲解
收藏 0 赞 0 分享

方便的大家admin及admin888 经过 md5加密后16位和32位代码

方便的大家admin及admin888 经过 md5加密后16位和32位代码
收藏 0 赞 0 分享

可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集

可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集
收藏 0 赞 0 分享

asp动态级联菜单代码

asp动态级联菜单代码
收藏 0 赞 0 分享

ASP中经常使用的SQL语句与教程说明

ASP中经常使用的SQL语句与教程说明
收藏 0 赞 0 分享

实例分析之用ASP编程实现网络内容快速查找的代码

实例分析之用ASP编程实现网络内容快速查找的代码
收藏 0 赞 0 分享

服务端 VBScript 与 JScript 几个相同特性的写法与示例

服务端 VBScript 与 JScript 几个相同特性的写法与示例
收藏 0 赞 0 分享

ASP 环境下 VBS 事件应用 示例代码

ASP 环境下 VBS 事件应用 示例代码
收藏 0 赞 0 分享

asp 之上传漏洞终结篇

asp 之上传漏洞终结篇
收藏 0 赞 0 分享
查看更多