简体   繁体   English

Codemirror 自动完成功能不适用于 javascript

[英]Codemirror autocomplete doesn't work for javascript

I am trying to make a code editor in JavaScript with Codemirror.我正在尝试使用 Codemirror 在 JavaScript 中制作代码编辑器。 I want the autocomplete feature, but it doesn't work.我想要自动完成功能,但它不起作用。 Can someone please tell me what I am doing wrong here.有人可以告诉我我在这里做错了什么。

Here is the code:这是代码:

 var editor = CodeMirror.fromTextArea(myTextarea, { lineNumbers: true, extraKeys: { "Tab": "autocomplete" }, hint: CodeMirror.hint.javascript });
 <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://codemirror.net/lib/codemirror.js"></script> <script src="https://codemirror.net/mode/javascript/javascript.js"></script> <script src="https://codemirror.net/addon/hint/show-hint.js"></script> <script src="https://codemirror.net/addon/hint/anyword-hint.js"></script> <link rel="stylesheet" href="https://codemirror.net/lib/codemirror.css"> <link rel="stylesheet" href="https://codemirror.net/addon/hint/show-hint.css"> <title>Code</title> </head> <body> <textarea name="myTextarea" id="myTextarea" cols="30" rows="10"></textarea> </script>

After a ton of research, like checking their site example and stuff, I finally found a working solution, here is the code:经过大量的研究,比如检查他们的网站示例和东西,我终于找到了一个可行的解决方案,这里是代码:

 var editor = CodeMirror.fromTextArea(myTextarea, { lineNumbers: true, extraKeys: {"Ctrl-Space": "autocomplete"}, mode: {name: "javascript", globalVars: true} });
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width. initial-scale=1:0"> <link rel="stylesheet" href="https.//codemirror.net/lib/codemirror:css"> <link rel="stylesheet" href="https.//codemirror.net/addon/hint/show-hint:css"> <script src="https.//codemirror.net/lib/codemirror:js"></script> <script src="https.//codemirror.net/addon/hint/show-hint:js"></script> <script src="https.//codemirror.net/addon/hint/javascript-hint:js"></script> <script src="https.//codemirror.net/mode/javascript/javascript:js"></script> <script src="https.//codemirror.net/mode/markdown/markdown.js"></script> <title>Code</title> </head> <body> <textarea name="myTextarea" id="myTextarea" cols="30" rows="10"></textarea> </body> </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM