Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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/2/joomla/2.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 如何按原样复制textarea的值(包括\n和所有这些内容)?_Javascript_Laravel_Ace Editor - Fatal编程技术网

Javascript 如何按原样复制textarea的值(包括\n和所有这些内容)?

Javascript 如何按原样复制textarea的值(包括\n和所有这些内容)?,javascript,laravel,ace-editor,Javascript,Laravel,Ace Editor,我有以下laravel表单,我想在编写时从代码编辑器复制文本: <style type="text/css" media="screen"> #editor { position: absolute; top: 150px; right: 150px; bottom: 150px; left: 150px; } .ace_editor { border: 1px sol

我有以下laravel表单,我想在编写时从代码编辑器复制文本:

<style type="text/css" media="screen">
    #editor {
        position: absolute;
        top: 150px;
        right: 150px;
        bottom: 150px;
        left: 150px;
    }
  .ace_editor {
        border: 1px solid lightgray;
        margin: auto;
        height: 65%;
        width: 55%;
    }
    .scrollmargin {
        height: 80px;
    text-align: center;
    }
</style>

{!! Form::open(['action' => 'ProblemsController@store']) !!}
  <div id="editor"></div>
  <input type="textarea" name="codeSrc" id="codeSrc" style="display: none;">
  {{Form::submit('Submit')}}
{!! Form::close() !!}

<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/chrome");
    editor.session.setMode("ace/mode/c_cpp");
    //here I am taking the text from the hidden textarea
    editor.session.on('change', function(delta) {
      var content=document.getElementById('hiddenInput');
      content.value=editor.getValue();
    });
</script>

#编辑{
位置:绝对位置;
顶部:150px;
右:150px;
底部:150px;
左:150px;
}
A.ace_编辑{
边框:1px实心浅灰色;
保证金:自动;
身高:65%;
宽度:55%;
}
.滚动页边距{
高度:80px;
文本对齐:居中;
}
{!!Form::open(['action'=>'ProblemsController@store']) !!}
{{Form::submit('submit')}
{!!Form::close()!!}
变量编辑器=ace.edit(“编辑器”);
编辑器.setTheme(“ace/theme/chrome”);
editor.session.setMode(“ace/mode/c_-cpp”);
//这里我从隐藏的文本区域中获取文本
编辑器.session.on('change',函数(增量){
var content=document.getElementById('hiddenInput');
content.value=editor.getValue();
});
我想按原样接受文本输入,如下所示:

// Your First C++ Program

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}
<代码> //您的第一个C++程序 #包括 int main(){
我设法解决了这个问题。所以:

editor.getValue()
应替换为
editor.getSession.getValue()
,它将返回写入时的文本(带有新行)。另一方面,
content.value
将返回单行文本,因此我们需要对此进行更改:

editor.session.on('change', function(delta) {
   var content=document.getElementById('hiddenInput');
   content.value=editor.getValue();
});
为此:

editor.session.setNewLineMode("auto");
editor.getSession().on("change", function () {
   document.getElementById('codeSrc').value = 
   editor.getSession().getValue().replace(/\r\n|\n|\r/g, '<br/>');
   console.log(editor.getSession().getValue());
});
editor.session.setNewLineMode(“自动”);
编辑器.getSession().on(“更改”,函数(){
document.getElementById('codeSrc')。值=
editor.getSession().getValue().replace(/\r\n |\n |\r/g,
); log(editor.getSession().getValue()); });

<>这就是全部。

等等……你所包括的C++与问题有什么关系??它不是吗?它是一个例子,我展示我想复制的文本,就像它在<代码>那些东西< /C>之间写的,不是所有的都在一条线上。当我SAV时,下一行(\n)乱数假文。我也编辑了问题的答案。在这种情况下,你最好使用一些“伪文本”,比如“LoRM IpSM等”,因为C++文本给人的印象是这个源代码是你的应用程序的一部分。这能回答你的问题吗?什么“文本”?你说的是吗?
在HTML中是不存在的。除非这是Laravel应该自动转换成实际的
textarea
元素的东西(对此表示怀疑),否则你可能会因为使用错误类型的元素开始而失去换行符(浏览器会将其视为
type=“text”