我有一个String串 比如s的值为 <div style="float:left;display:inline">...</div>
我该怎么样在<textarea>中按html格式来正确显示呢
万分感谢
------解决方案--------------------
你要将html放在一个div里,不要用textarea了,直接用div当编辑框吧,设置了contenteditable以后就可以当做textarea用了,给你一个例子
<html>
<body>
<script>
window.onload = function(e) {
var btn = document.getElementById("btn")
var editor = document.getElementById("editor")
btn.addEventListener("click", function() {
var html = '<div style="color:red">------------</div>'
editor.innerHTML += html
}, false)
}
</script>
<div id="editor" contenteditable="true" style="width:400px;height:300px;overflow:auto;border:1px solid black;"></div>
<button id="btn">添加内容</button>
</body>
</html>