嗷嗷答 - 嗷嗷好的公务员考试网络答题平台

TE文章中插入代码运行框

作者:不烦恼 发布时间:January 10, 2012 分类:快乐学习

为今后补习JS而准备。

为了集成在MagikeEditor编辑器插件中,修改了插件中magike_editor.js的原代码

  1. function createDefaultButtons()
  2. {
  3. // …………
  4. // insert
  5. addButton('RunCode', '<textarea class=&quot;runcode&quot;>', '</textarea><input type=&quot;button&quot; value=&quot;运行&quot; class=&quot;runbutton&quot; onclick=&quot;runCode(this);&quot; />');
  6. }

运行框的JS代码

  1. function runCode(obj){
  2. var winname = window.open('', "_blank", '');
  3. winname.document.open('text/html', 'replace');
  4. winname.opener = null;
  5. winname.document.write($(obj).prev().val());
  6. winname.document.close();
  7. }

运行框的CSS代码
  1. .runcode{width:500px; height:100px; padding:8px; border:1px solid #dddddd;vertical-align:middle;}
  2. .runbutton{width:40px; height:118px; border:1px solid #dddddd; background-color:#f4f4f4;vertical-align:middle; margin-left:-1px; color:#444;cursor:pointer;}

已有 4 条评论 »

  1. 这个不错,收下了。

  2. 这个很强大,以后没事就来测试下js

    1. 试了下alert('ok');貌似在新开页是body内容,不是js代码,前面加个就不一样,搞不懂

  3. 这个不错,收下了,以后可以直接看运行效果了

添加新评论 »