强大号码库资源任选,方便,快捷,快速开通。
咨询热线:400-1100-266
给zblog添加上“运行代码”的功能,因为经常要贴出一些代码,所以用上这个“运行代码”的功能,是最为方便的了。
下面转一下方法,相关讨论参见“z-blog论坛”。
如果你按如下步骤设置完毕,调用这个功能的方法是,在文章编辑区中加入[ code ]你的代码[ /code ],因为这是是演示,所以“中括号”与code之间留了空格,你实际用的时候,请去掉空格。
1、在zb_system/script/common.js里面增加
//*********************************************************
//目的:代码运行框
//输入:obj
//返回:
//*********************************************************
functioncopycode(obj){
varrng=document.body.createTextRange();
varobj1=document.getElementById(obj)
rng.moveToElementText(obj1);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
functionrunCode(obj){
varwinname=window.open('',"_blank",'');
varobj1=document.getElementById(obj)
winname.document.open('text/html','replace');
winname.opener=null//防止恶意修改
winname.document.writeln(obj1.value);
winname.document.close();
}
functionsaveCode(obj){
varwinname=window.open('','_blank','top=10000');
varobj1=document.getElementById(obj)
winname.document.open('text/html','replace');
winname.document.writeln(obj1.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}
2、zb_system/FUNCTION/c_function.asp,查找
FunctionTransferHTML(ByValsource,ByValpara)
注释掉或者删掉下面这句
IfInstr(para,"[space]")>0Thensource=Replace(source,""," ")
查找
objRegExp.Pattern="([CODE])(.+?)([/CODE])" strContent=objRegExp.Replace(strContent,"<textareaclass=""code""rows=""10""cols=""50"">$2</textarea>")
替换为
DimcodeNum,rndStr
codeNum=0
Randomize
rndStr=int(rnd*100)
strContent=objRegExp.Replace(strContent,"<textareaclass=""code""name=""code"&rndStr&codeNum&"""id=""code"&rndStr&codeNum&"""rows=""10""cols=""50"">$2</textarea><br/><inputtype=""button""value=""运行代码""onclick=""runCode('code"&rndStr&codeNum&"')""><inputtype=""button""value=""""onclick=""copycode('code"&rndStr&codeNum&"')""><inputtype=""button""value=""另存代码""onclick=""saveCode('code"&rndStr&codeNum&"')"">提示:您可以先修改部分代码再运行")
codeNum=codeNum+1
3、重建所有页面
4、最后,试一下效果,因为在“可视编辑”状态中,编辑器不知给代码做了什么处理,导致不能运行,所以建议一些复杂代码,还是用“源代码”保险。
[code]
-
Home
-
About Me
-
Portfolio
-
Blog
-
Resources
-
Contact Me
-
Home
-
About Me
-
Portfolio
-
Blog
-
Resources
-
Contact Me
-
Home
-
About Me
-
Portfolio
-
Blog
-
Resources
-
Contact Me
-
Home
-
About Me
-
Portfolio
-
Blog
-
Resources
-
Contact Me
[/code]
时间:9:00-21:00 (节假日不休)
版权所有:巨人网络(扬州)科技有限公司
总部地址:江苏省信息产业基地11号楼四层
《增值电信业务经营许可证》 苏B2-20120278

