当我将代码从 textarea 复制到 div 然后返回时,内容不再相同。
<!doctype html>
<html>
<head>
</head>
<body>
<textarea id="ta" rows="10" cols="120"><p> "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation <ul><li>sfsD</li><li>sf234fw</li></ul> ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." </p></textarea>
<br>
<button>Button</button>
<div id="container"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$('button').click(function(){
$('#container').html($('#ta').val());
$('#ta').val($('#container').html());
});
</script>
</body>
</html>
因此,当我将文本从 textarea 复制到 div 时,一切都很好。但是当我从 div 复制回 textarea 时,现在的值是
<p> "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation </p>
<ul><li>sfsD</li><li>sf234fw</li></ul> ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum." <p></p>
我不确定为什么会发生这种情况或如何解决?!有任何想法吗?这发生在 FF 和 chrome 中。