我有一个 contenteditable div,其中包含文本和一些 html 代码。我想将内容(文本和代码)从这个 div 移动到 textarea。我有 movecontent javascript,但它只移动文本.. 任何人都可以帮助我吗?
<html>
<head>
<script type="text/javascript">
function MoveContent () {
var srcObj = document.getElementById ("src");
var destObj = document.getElementById ("dest");
if (document.createRange) { // all browsers, except IE before version 9
var rangeObj = document.createRange ();
rangeObj.selectNodeContents (srcObj);
var documentFragment = rangeObj.extractContents ();
destObj.appendChild (documentFragment);
}
}
</script>
</head>
<body>
<div id="src" style="background-color:#e0a0b0; width:300px; height:50px;">The <br> <b>contents</b> of the <i>source</i> element.</div>
<textarea id="dest" style="width: 500px; height:100px;"></textarea>
<br /><br />
<button onclick="MoveContent ();">Move the contents!</button>
</body>