地质所 沉降监测网建设项目
zmk
2024-05-15 9e3afc6d0fa514f986d3fea40fa23124e6fb5070
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="utf-8" />
        <title>插入字符 / 设置和获取光标位置 / 设置、获取和替换选中的文本 - Editor.md examples</title>
        <link rel="stylesheet" href="css/style.css" />
        <link rel="stylesheet" href="../css/editormd.css" />
        <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
    </head>
    <body>
        <div id="layout">
            <header>
                <h1>插入字符 / 设置和获取光标位置 / 设置、获取和替换选中的文本</h1> 
                <p>Insert value & Set / Get cursor & Set / Get / Replace selection</p> 
                <br/>
                <div class="btns" style="margin:0">
                    <button id="btn1">设置光标位置 (line:1, ch:2)</button>
                    <button id="btn2">获取光标位置</button>
                    <button id="btn3">设置选中文本 ({line:1, ch:0}, {line:5, ch:100})</button>
                    <button id="btn4">获取选中文本</button>
                    <button id="btn5">替换选中文本为 "$$$$$$$$$"</button>
                    <button id="btn6">在光标处插入 "????"</button>                    
                </div>
            </header>
            <div id="test-editormd">  
                <textarea style="display:none;">### Examples
 
```javascript
var testEditormd;
 
$(function() {
    testEditormd = editormd("test-editormd", {
        width: "90%",
        height: 640,
        path : '../lib/'
    });
});
 
$("#btn1").click(function(){
    testEditormd.setCursor({line:1, ch:2});
});
 
$("#btn2").click(function(){
    console.log("getCursor =>", testEditormd.getCursor());
});
 
$("#btn3").click(function(){
    testEditormd.setSelection({line:1, ch:0}, {line:5, ch:100});
});
 
$("#btn4").click(function(){
    console.log("getSelection =>", testEditormd.getSelection());
});
 
$("#btn5").click(function(){
    testEditormd.replaceSelection("$$$$$$$$$");
});
 
$("#btn6").click(function(){
    testEditormd.insertValue("????");
});
```
</textarea>
            </div>
        </div>
        <script src="js/jquery.min.js"></script>
        <script src="../editormd.js"></script>   
        <script type="text/javascript">
            var testEditormd;
 
            $(function() {
                testEditormd = editormd("test-editormd", {
                    width: "90%",
                    height: 640,
                    path : '../lib/'
                });
                
                $("#btn1").click(function(){
                    testEditormd.setCursor({line:1, ch:2});
                    testEditormd.focus();
                });
                
                $("#btn2").click(function(){
                    console.log("getCursor =>", testEditormd.getCursor());
                    testEditormd.focus();
                });
                
                $("#btn3").click(function(){
                    testEditormd.setSelection({line:1, ch:0}, {line:5, ch:100});
                    testEditormd.focus();
                });
                
                $("#btn4").click(function(){
                    console.log("getSelection =>", testEditormd.getSelection());
                    testEditormd.focus();
                });
                
                $("#btn5").click(function(){
                    testEditormd.replaceSelection("$$$$$$$$$");
                    testEditormd.focus();
                });
                
                $("#btn6").click(function(){
                    testEditormd.insertValue("????");
                    testEditormd.focus();
                });
            });
        </script>
    </body>
</html>