Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ACE编辑器:textarea始终将空值传递给表单_Javascript_Html_Ace Editor - Fatal编程技术网

Javascript ACE编辑器:textarea始终将空值传递给表单

Javascript ACE编辑器:textarea始终将空值传递给表单,javascript,html,ace-editor,Javascript,Html,Ace Editor,我正在使用Flask进行web开发。我以以下方式将ACE编辑器集成到表单中: <textarea maxlength="10000" rows="20" cols="80" name="tc001_input" form="usrform" data-editor="markdown" id="editor">{{input}}</textarea> <form action="/tc001" id="usrform" method = "post">

我正在使用Flask进行web开发。我以以下方式将ACE编辑器集成到表单中:

<textarea  maxlength="10000" rows="20" cols="80" name="tc001_input" form="usrform" data-editor="markdown" id="editor">{{input}}</textarea>
<form action="/tc001" id="usrform" method = "post">
  <input type="submit">

  <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js"></script>
<script type="text/javascript">
    // https://gist.github.com/duncansmart/5267653
    // find each text area marked to have an editor
    $('textarea[data-editor]').each(function() {
        var textarea = $(this);
        var mode = textarea.data('editor');
        // create the editor div
        var div = $('<div>', {
            'width': textarea.outerWidth(),
            'height': textarea.outerHeight(),
            'class': textarea.attr('class')
        }).insertBefore(textarea);
        // hide the original text area
        textarea.hide();
        // configure the editor
        var editor = ace.edit(div[0]);
        var session = editor.getSession();
        editor.setTheme("ace/theme/github");
        session.setValue(textarea.val());
        session.setMode('ace/mode/' + mode);
        session.setNewLineMode('unix');
        session.setTabSize(4);
        session.setUseSoftTabs(true);
        session.setUseWrapMode(true);
        // update the text area before submitting the form
        textarea.closest('form').submit(function() {
            textarea.val(editor.getSession().getValue());
        });
    });
</script>
</form>

然后我得到空白数据。在提交之前,我已将abc数据输入文本区域。有什么问题吗?

问题是您的textarea不在表单中,因此textarea.closest'form'不起作用,这里有一个修改版本,它使用了最新的ace,并且textarea的.form属性起作用

文本区的内容 //查找标记为具有编辑器的每个文本区域 $'textarea[data editor]'。每个函数{ var textarea=$this; var mode=textarea.data'editor'; //创建编辑器div var div=${ “宽度”:textarea.outerWidth, “高度”:textarea.outerHeight, 'class':textarea.attr'class' }.插入BeforeTextArea; //隐藏原始文本区域 textarea.hide; //配置编辑器 var editor=ace.editdiv[0]{ 值:textarea.val.replacetextarea,ace!, 主题:ace/theme/github, 模式:“ace/mode/”+模式, newLineMode:“unix”, tabSize:4, useSoftTabs:正确, 是的, }; //在提交表单之前更新文本区域 textarea[0]。form.addEventListenersubmit,函数{ textarea.valeditor.getSession.getValue; }; };
request.form['tc001_input']