[英]codemirror how to install
I am not sure what to do after this: 我不知道该怎么办:
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<script>
var editor = CodeMirror.fromTextArea(myTextarea, {
mode: "text/html"
});
</script>
can someone help me? 有人能帮我吗?
does this points you to the right direction? 这是否为您指明了正确的方向?
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<script src="mode/javascript/javascript.js"></script>
<script src="addon/fold/foldcode.js"></script>
</head>
<body>
<form style="width:500px;">
<textarea id="code" name="code">
alert("HI");
//says HII
</textarea>
</form>
<script>
window.onload = function() {
window.editor = CodeMirror.fromTextArea(code, {
mode: "javascript",
lineNumbers: true,
lineWrapping: true,
foldGutter: {
rangeFinder: new CodeMirror.fold.combine(CodeMirror.fold.brace, CodeMirror.fold.comment)
},
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
});
};
</script>
</body>
</html>
First: you have to select the first element that matches the selector. 首先:您必须选择与选择器匹配的第一个元素。
$("#editor") won't do it, it has to be $("#editor")[0] $(“#editor”)不会这样做,它必须是$(“#editor”)[0]
Second: The following code is all you need to get it to work: 第二: 下面的代码是使其正常工作所需的全部:
window.onload = function () { var editor = CodeMirror.fromTextArea($("#editor")[0], { lineNumbers: true, lineWrapping: true, }); };
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.29.0/codemirror.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.29.0/codemirror.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.29.0/mode/javascript/javascript.js"></script> </head> <body> <p>Type some javascript below</p> <textarea id="editor"></textarea> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.