如何在网页 运行 时更改 CodeMirror 设置?
How do you change CodeMirror settings while the web page is running?
我正在使用 CodeMirror 将我的文本区域转换为语法荧光笔。代码看起来像这样:
<textarea id="editor">
<html>
<body>
<h1>Some Heading</h1>
</body>
</html>
</textarea>
<input type="checkbox" id="ln" checked/>
<label for="ln">Toggle Line Numbers</label>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
mode: "javascript",
theme: "cobalt",
lineNumbers: true
});
editor.setSize(1000, 500)
</script>
一切正常。但我无法在配置后更改任何设置。我想知道,当网页为 运行?
时,如何更改行号、关闭或打开或任何其他模式
您可以使用以下方法在初始化后更改 CodeMirror 设置。
editor.setOption("OPTION_NAME", YOUR_VALUE); // Structure
editor.setOption("lineNumbers", false); // Example
有关 CodeMirror 选项的详细信息,请参阅 CodeMirror 文档站点上的#setOption and #event_optionChange。
我正在使用 CodeMirror 将我的文本区域转换为语法荧光笔。代码看起来像这样:
<textarea id="editor">
<html>
<body>
<h1>Some Heading</h1>
</body>
</html>
</textarea>
<input type="checkbox" id="ln" checked/>
<label for="ln">Toggle Line Numbers</label>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
mode: "javascript",
theme: "cobalt",
lineNumbers: true
});
editor.setSize(1000, 500)
</script>
一切正常。但我无法在配置后更改任何设置。我想知道,当网页为 运行?
时,如何更改行号、关闭或打开或任何其他模式您可以使用以下方法在初始化后更改 CodeMirror 设置。
editor.setOption("OPTION_NAME", YOUR_VALUE); // Structure
editor.setOption("lineNumbers", false); // Example
有关 CodeMirror 选项的详细信息,请参阅 CodeMirror 文档站点上的#setOption and #event_optionChange。