编程语言 select droptown Codemirror
Programming language select droptown Codemirror
我想要 codemirror. 的语言选择下拉菜单
我看过 但我无法理解它的正面或反面。任何人都可以为我清理它或提供解决方案吗?提前致谢!
您可以创建一个对象 {'go':'text/x-go','javascript':'text/javascript'}
等等并对其进行索引。
var editor = CodeMirror.fromTextArea(document.getElementById('edit'),{lineNumbers:true,mode:'text/x-go'});
function select(x) {
var optionText = x.options[x.selectedIndex].innerText;
var modes = {'Golang':'text/x-go','Javascript':'text/javascript','Css':'text/css'};
editor.setOption('mode', modes[optionText]);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/codemirror.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/codemirror.min.css" rel="stylesheet"/><script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/mode/javascript/javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/mode/go/go.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/mode/css/css.min.js"></script>
<select onchange="select(this)">
<option>Golang</option>
<option>Javascript</option>
<option>Css</option>
</select> <br>
<textarea id="edit">
//Try do package main and change modes
</textarea>
我想要 codemirror. 的语言选择下拉菜单
我看过
您可以创建一个对象 {'go':'text/x-go','javascript':'text/javascript'}
等等并对其进行索引。
var editor = CodeMirror.fromTextArea(document.getElementById('edit'),{lineNumbers:true,mode:'text/x-go'});
function select(x) {
var optionText = x.options[x.selectedIndex].innerText;
var modes = {'Golang':'text/x-go','Javascript':'text/javascript','Css':'text/css'};
editor.setOption('mode', modes[optionText]);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/codemirror.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/codemirror.min.css" rel="stylesheet"/><script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/mode/javascript/javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/mode/go/go.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.38.0/mode/css/css.min.js"></script>
<select onchange="select(this)">
<option>Golang</option>
<option>Javascript</option>
<option>Css</option>
</select> <br>
<textarea id="edit">
//Try do package main and change modes
</textarea>