codemirror javascript在线脚本编辑器

    <title>codeMirror测试</title>
    <link type="text/css" rel="stylesheet" href="codemirror/lib/codemirror.css" />
    <link type="text/css" rel="stylesheet" href="codemirror/theme/eclipse-ext.css" />
    <link type="text/css" rel="stylesheet" href="codemirror/addon/hint/show-hint.css" />
    <script type="text/javascript" src="codemirror/lib/codemirror.js"></script>
    <script type="text/javascript" src="codemirror/mode/javascript/javascript.js"></script>
    <script type="text/javascript" src="codemirror/addon/hint/show-hint.js"></script>
    <script type="text/javascript" src="codemirror/addon/hint/javascript-hint.js"></script>

    <style>.CodeMirror {border: 1px solid black;}</style>

<h2>Autocomplete Demo</h2>
< textarea id="code" name="code">< /textarea>
< button type="submit" name="button" id="button" value="if{ &#10 &#10}else{&#10 &#10}">if..else< /button>

< script src="jquery-1.11.3.js">< /script>
< script>
    CodeMirror.velocityContext = "server software env";  //提取到外部,方便从后台获取数据
    CodeMirror.velocityCustomizedKeywords = "server.ip server.cache software.conf software.version software.tags.count";
    var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
        lineNumbers: true,
        extraKeys: {"Ctrl-Q": "autocomplete"},  //避免热键冲突  
        mode: {name: "javascript", globalVars: true}
    });
    $("#button").click(function () {
        editor.replaceSelection("if{\n\n}else{\n\n}")
    });
//    editor.on('change', function() {
//        editor.showHint();  //满足自动触发自动联想功能
//    });
< /script>
发布了38 篇原创文章 · 获赞 5 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_39423672/article/details/79694366