利用ace.js编写一个JavaScript编辑器(带智能补全)
来源:互联网 发布:netflix ribbon源码 编辑:程序博客网 时间:2024/09/21 08:16
<html lang="en"> <head> <title>javascript编辑器</title> <style type="text/css" media="screen"> #aaa { width:50%; } #editor { width:100%; padding-bottom: 35%; } #iframe1{ width:100%; background: #505050; border:1px; } #rundata{ width:100%; border:1px; } </style> </head> <body> <div id="aaa"> <div id="editor"></div> <div ><button id="rundata" onclick="rundata()">RUN</button></div> <div ><iframe id="iframe1"></iframe></div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js" type="text/javascript" charset="utf-8"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ext-language_tools.js" type="text/javascript" charset="utf-8"></script> <script> ace.require("ace/ext/language_tools"); var editor = ace.edit("editor"); editor.setOptions({ // enableBasicAutocompletion: true, // enableSnippets: true, enableLiveAutocompletion: true,//只能补全 }); editor.setTheme("ace/theme/monokai");//monokai模式是自动显示补全提示 editor.getSession().setMode("ace/mode/javascript");//语言 editor.setFontSize(16); </script> <script> function rundata(){ //获取输入框内的数据 var text = document.getElementById('editor').innerText; // 先清空iframe if(document.getElementById("iframe1").contentWindow.document.body!=null){ var iframe = document.getElementById("iframe1").contentWindow.document.body.innerText = ""; } //添加script标签,去掉开头的行号 var ctext = "<script>"+text.replace(/\d\n/g, "")+'<\/script>'; console.log(ctext); //替换控制台打印(伪装效果) if(ctext.indexOf("console.log")>0){ ctext = ctext.replace("console.log", "document.write"); } console.log(ctext); //将输入框内的数据传给iframe iframe = document.getElementById('iframe1').contentDocument.write(ctext); } </script> </body></html>
效果:
ace地址:https://github.com/ajaxorg/ace-builds/
阅读全文
0 0
- 利用ace.js编写一个JavaScript编辑器(带智能补全)
- Atom编辑器折腾记_(13)JS代码智能提示补全(插件:atom-ternjs)
- Atom编辑器折腾记_(15)JS代码片段补全(插件:javascript-snippets)
- vim智能补全
- Vim-智能补全
- 自动补全、智能提示、输入容错 JavaScript云插件
- GVim智能补全clang
- vim的智能补全
- vim 智能补全 clang_complete
- js自动补全——接上一篇JavaScript自动补全
- javaScript自动补全
- javascript 自动补全
- 编写一个非常简单的 JavaScript 编辑器
- js 自动补全
- js 自动补全
- js 自动补全
- js自动补全
- vi/vim使用进阶: 智能补全
- char * 与 string 类型相互转换方法--C/C++
- matlab函数bsxfun、crossvalind、ismember,kmean
- Java并发编程:volatile关键字解析
- Java 内存溢出(java.lang.OutOfMemoryError)的常见情况和处理方式总结
- mysql时间的转换
- 利用ace.js编写一个JavaScript编辑器(带智能补全)
- 使用图标字体Font Awesome
- [swagger]swagger接口规范学习笔记
- JAVA中sort函数的使用方法的个人总结
- Android Studio中Gradle使用详解
- IP地址 boost asio
- Duilib配置的下载器
- 单例模式
- python3 os模块笔记