当我从 div 获取值时遇到这个问题:
function sync(){
var n1 = document.getElementById('editor').value;
alert(n1);
var n2 = document.getElementById('news');
n2.value = n1;
}
带 ID 的 diveditor
看起来像这样:
<div class='message' id='editor' contenteditable="true" onkeyUp='sync()' style="color: black"></div>
当我在该 div 中放入某些内容时,它会提醒我未定义,并且它也会出现在我粘贴的文本区域中。所以问题显然是这样的:
var n1 = document.getElementById('editor').value;
我究竟做错了什么?
Try this
var n1 = document.getElementById('editor').innerHTML; // or innerText, or textContent
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)