CodeMirror示例demo

CodeMirror示例demo

<html>
<head>
    <link rel="stylesheet" href="codemirror.css">  <!-- 引入CSS文件 -->
    <script src="codemirror.js"></script>  <!-- 引入JS文件 -->
</head>
<body>
    <textarea id="code" name="code">http://www.cnblogs.com/oldphper</textarea>
    <script>
        var editor = CodeMirror.fromTextArea(document.getElementById("code"), {  // 标识到textarea
            value : "http://www.cnblogs.com/oldphper",  // 文本域默认显示的文本
            mode : "text/html",  // 模式
            // theme : "",  // CSS样式选择
            indentUnit : 2,  // 缩进单位,默认2
            smartIndent : true,  // 是否智能缩进
            tabSize : 4,  // Tab缩进,默认4
            readOnly : false,  // 是否只读,默认false
            showCursorWhenSelecting : true,
            lineNumbers : true  // 是否显示行号
            // .. 还有好多,翻译不完。需要的去看http://codemirror.net/doc/manual.html#config
        });
    </script>
</body>
</html>
function fun() {
    ob = "";
    //alert(editor.getValue()); // 得到所有内容
    //editor.setValue("abc"); // 将编辑器内容改为"abc"

    // 0为起点,2行第3个字母到2行第5个字母
    //alert(editor.getRange({line:1,ch:2},{line:1,ch:5}));  //得到
    //editor.replaceRange("shashasha",{line:1,ch:2},{line:2,ch:5});

    //alert(editor.getLine(2));   // 第三行数据
    //alert(editor.lineCount());   // 总共几行
    //alert(editor.firstLine());   // 首行数0
    //alert(editor.lastLine());   // 末行数19,共20行
    //ob = editor.getLineHandle(1);   // 第二行数据句柄
    //alert(editor.getLineNumber(ob)); // 行句柄在哪行
    //editor.eachLine(0,2,alert(ob));

    //ob = editor.changeGeneration();    // 编辑动作次数,1次起
    //editor.markClean();   // 清除动作
    //editor.isClearn();    // 是否清除

    //ob = editor.getSelection();   // 获得选中的数据一条
    //ob = editor.getSelections();  // 获得选中数据多条
    editor.replaceSelection("ttttttt"); // 选中替换,一条根多条都替换,不选中则在光标处插入
    //editor.replaceSelections(["aaa","bbb"]); // 选中替换,多条对多选
    //editor.setSelection();  //设置选中
    //editor.setSelections();  //设置选中
    //ob = editor.listSelections(); //boj
    //ob = editor.somethingSelected(); // 是否有选中
    //editor.addSelection({line:2,ch:6}, {line:1,ch:2});  // 选中此段

    //ob = editor.getCursor();    // ob['line']、['ch']
    //editor.setCursor(2);    // 设置光标位置

    //ob = editor.hasFocus();   // focus?全false

    //editor.addOverlay("aaaaa"); //..
    //editor.removeOverlay("aaaaa"); //..

    //ob = editor.getDoc();   // 文档对象,很多
    //ob = editor.getEditor();   //..

    //ob = editor.setBookmark({line:1,ch:3}); // 书签对象

    //editor.addWidget({line:1,ch:2},"<if></if>",true); //添加部件

    //editor.setSize(1100,1100);    //设置宽高
    //editor.scrollTo(800,300); // 设置滚动条位置

    //editor.cursorCoords({line:1,ch:2},"aaaaaa"); //..

    //for (var i in ob)
    //    alert(i);
    //alert(ob);
}

 上一篇
Base64转换 Base64转换
Base64转换import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import java.io.*; /** * 文件Base64转换 * Created b
2019-08-19
下一篇 
Cookie和Session Cookie和Session
Cookie和Session一、cookie机制和session机制的区别具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案。同时我们也看到,由于服务器端保持状态的方案在客户端也需要
2019-08-19
  目录