【发布时间】:2015-03-24 09:45:01
【问题描述】:
我一直在使用 CodeMirror 为我的 textarea 提供 HTML 语法高亮,但我也希望能够单击一个按钮以在单独的 div 中呈现 HTML 代码。
这就是我目前所拥有的功能:
<script>
/*create the CodeMirror editor*/
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {lineNumbers: true});
/*Grab the text from the editor and return it*/
function extractCode() {
var text = editor.mirror.getValue();
return text;
}
</script>
<script>
/*When the showmeImg image is clicked, grab the code with extractCode and send it to the output div*/
$(document).ready(function(){
$("#showmeImg").click(function(){
$("#output").html($(extractCode).val());
});
});
</script>
我对 javascript 和 jquery 还很陌生,所以我不确定我是否做得对。任何帮助表示赞赏!
【问题讨论】:
标签: javascript jquery html codemirror