使用javascript从div获取价值:始终未定义

Sje*_*kie 5 html javascript undefined

当我从div获取值时,我遇到了这个问题:

function sync(){
    var n1 = document.getElementById('editor').value;
    alert(n1);
    var n2 = document.getElementById('news');
    n2.value = n1;
}
Run Code Online (Sandbox Code Playgroud)

带id的div editor看起来像这样:

<div class='message'  id='editor' contenteditable="true" onkeyUp='sync()' style="color: black"></div>
Run Code Online (Sandbox Code Playgroud)

当我在那个div中添加一些内容时,它会提醒我未定义,并且也会在textarea中进行粘贴.所以问题显然是由此:

var n1 = document.getElementById('editor').value;
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Ale*_* T. 12

试试这个

var n1 = document.getElementById('editor').innerHTML; // or innerText, or textContent
Run Code Online (Sandbox Code Playgroud)