【问题标题】:codemirror - multiple text areas not workingcodemirror - 多个文本区域不起作用
【发布时间】:2017-11-23 19:13:33
【问题描述】:

根据这里的问题Can codemirror be used on multiple textareas?

我已将确切的配置应用到我的页面,并且两个文本区域都没有被转换为代码镜像。

控制台也没有错误,我不确定我错过了什么?

我的代码如下:

<script src="{% static 'home/scripts/codemirror/codemirror.js' %}"></script>
<link href="{% static 'home/scripts/codemirror/codemirror.css' %}" rel="stylesheet">
<script src="{% static 'home/scripts/codemirror/django/django.js' %}"></script>
<script type="text/javascript"> 
function editor(id) {
        CodeMirror.fromTextArea(id, {
            height: "400px",
            continuousScanning: 500,
            lineNumbers: true
        });
    }
editor('id_config');
editor('id_remote_config');
</script>
<form id="edit_template" action="" method="post">
    {% csrf_token %}
    {{ TemplateForm.template_name }}
    {{ TemplateForm.config }}
    {{ TemplateForm.remote_config }}
    <input type='submit' value='Update' />
</form>

django 表单使用我指定的 ID 呈现文本区域

有人有什么想法吗? 谢谢

【问题讨论】:

    标签: javascript codemirror


    【解决方案1】:

    在您致电editor() 时,这些文本区域不存在。将您的脚本标签移动到表单下方或在窗口加载事件处理程序中调用editor()

    【讨论】:

    • 我将 中的所有内容都移到了表单下方,还是什么都没有?
    • 浏览器控制台出错?
    • TypeError: textarea.getAttribute 不是函数。 (在 'textarea.getAttribute("autofocus")' 中,'textarea.getAttribute' 未定义)- 在 codemirror 9512
    • 添加了以下内容,它可以工作 var config = editor(document.getElementById('id_config')); var remote_config = editor(document.getElementById('id_remote_config'));
    猜你喜欢
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 2016-08-16
    相关资源
    最近更新 更多