asp下實(shí)現(xiàn)代碼的“運(yùn)行代碼”“復(fù)制代碼”“保存代碼”功能源碼
更新時(shí)間:2007年06月28日 00:00: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=運(yùn)行代碼 onclick=runCode(runcode"&i&")><input type=button class=input-code value=復(fù)制代碼 onclick=copycode(runcode"&i&")><input type=button class=input-code value=另存代碼 onclick=saveCode(runcode"&i&")><span class=code-tishi>提示:您可以先修改部分代碼再運(yùn)行</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
使用方法也很簡(jiǎn)單:
發(fā)表文章時(shí)需用使用“運(yùn)行代碼”功能的,主要前后加上
[ code ][/ code ]
比如:
[ code ]
<script type="text/javascript">
alert("簡(jiǎn)單吧");
</script>
[/ code ]
需要注意的是,在顯示的頁面要進(jìn)入以下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();
}
復(fù)制代碼 代碼如下:
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=運(yùn)行代碼 onclick=runCode(runcode"&i&")><input type=button class=input-code value=復(fù)制代碼 onclick=copycode(runcode"&i&")><input type=button class=input-code value=另存代碼 onclick=saveCode(runcode"&i&")><span class=code-tishi>提示:您可以先修改部分代碼再運(yùn)行</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
使用方法也很簡(jiǎn)單:
發(fā)表文章時(shí)需用使用“運(yùn)行代碼”功能的,主要前后加上
[ code ][/ code ]
比如:
復(fù)制代碼 代碼如下:
[ code ]
<script type="text/javascript">
alert("簡(jiǎn)單吧");
</script>
[/ code ]
復(fù)制代碼 代碼如下:
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();
}
相關(guān)文章
隨機(jī)調(diào)用n條數(shù)據(jù)的方法分析
隨機(jī)調(diào)用n條數(shù)據(jù)的方法分析...2007-07-07asp內(nèi)置對(duì)象 ObjectContext 事務(wù)管理 詳解
asp內(nèi)置對(duì)象 ObjectContext 事務(wù)管理 詳解...2007-11-11Coolite 中前臺(tái)獲取 GridPanel 當(dāng)前選擇行值的代碼
掌握獲取 GridPanel 當(dāng)前行的各個(gè)字段值的方法,需要的朋友可以參考下。2010-06-06ASP實(shí)現(xiàn)智能搜索實(shí)現(xiàn)代碼
asp下智能搜索功能的實(shí)現(xiàn),方便大家學(xué)習(xí)2008-06-06ASP開發(fā)中可能遇到的錯(cuò)誤信息中文說明大全(整理收集)
ASP開發(fā)中可能遇到的錯(cuò)誤信息中文說明大全(整理收集)...2007-03-03