Czy codemirror może być używany na wielu obszarach tekstowych?
Czy codemirror może być używany na więcej niż jednym obszarze tekstowym? Używam wielu tekstów generowanych dynamicznie.
<script type="text/javascript">
var editor = CodeMirror.fromTextArea('code', {
height: "dynamic",
parserfile: "parsecss.js",
stylesheet: "codemirror/css/csscolors.css",
path: "codemirror/js/"
});
</script>
Wolałbym ustawić klasę w textarea, aby połączyć ją z codemirror. Czy to możliwe? Innym sposobem rozwiązania tego problemu byłoby ustawienie wielu identyfikatorów. Powyższy kod ustawia ID "code", aby połączyć się z codemirror.
4 answers
Możesz wykonywać wiele wywołań do CodeMirror.fromTextArea
do' Codemirror-ify ' wielu obszarów tekstowych.
Jeśli chcesz mieć wiele tekstowych z tymi samymi opcjami, zawiń wywołanie Codemirror.fromTextArea
w funkcję, taką jak:
function editor(id)
{
CodeMirror.fromTextArea(id, {
height: "350px",
parserfile: "parsexml.js",
stylesheet: "css/xmlcolors.css",
path: "js/",
continuousScanning: 500,
lineNumbers: true
});
}
Możesz następnie zastosować go do swoich tekstów, takich jak:
editor('code1');
editor('code2');
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-18 19:19:59
Może być dla kogoś pomocne, załącz go do wielu tekstów używając klasy html:
<textarea class="code"></textarea>
<textarea class="code"></textarea>
<textarea class="code"></textarea>
<script type="text/javascript">
function qsa(sel) {
return Array.apply(null, document.querySelectorAll(sel));
}
qsa(".code").forEach(function (editorEl) {
CodeMirror.fromTextArea(editorEl, {
lineNumbers: true,
styleActiveLine: true,
matchBrackets: true,
theme: 'monokai',
});
});
</script>
Proszę napisać powód, jeśli przegłosowano..!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-22 18:11:39
Spróbuj tego:
<script>
var js_editor = document.getElementsByClassName("js_editor");
Array.prototype.forEach.call(js_editor, function(el) {
var editor = CodeMirror.fromTextArea(el, {
mode: "javascript",
lineNumbers: true,
styleActiveLine: true,
theme: 'duotone-light',
lineNumbers: true
});
// Update textarea
function updateTextArea() {
editor.save();
}
editor.on('change', updateTextArea);
});
</script>
<textarea class="js_editor"></textarea>
<textarea class="js_editor"></textarea>
<textarea class="js_editor"></textarea>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-11 08:25:27
Wypróbuj ten kod
function getByClass(sClass){
var aResult=[];
var aEle=document.getElementsByTagName('*');
for(var i=0;i<aEle.length;i++){
/*foreach className*/
var arr=aEle[i].className.split(/\s+/);
for(var j=0;j<arr.length;j++){
/*check class*/
if(arr[j]==sClass){
aResult.push(aEle[i]);
}
}
}
return aResult;
};
function runRender(type){
var aBox=getByClass("code_"+type);
for(var i=0;i<aBox.length;i++){
//alert(aBox[i].innerHTML);
//var editor = CodeMirror.fromTextArea(document.getElementById("code_javascript"), {
var editor = CodeMirror.fromTextArea(aBox[i], {
lineNumbers: true,
mode: "text/x-csrc",
keyMap: "vim",
matchBrackets: true,
showCursorWhenSelecting: true,
theme:"blackboard",
});
}
};
runRender('javascript');
runRender('c');
runRender('java');
runRender('bash');
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-24 09:23:10