如何使用选择文字
在contenteditable
中删除html标记
function testdemo() {
//what is next
....
}
之前:
<button onclick="testdemo();">RUN</button>
<div id="test" contenteditable="true">
<b>Lorem ipsum</b> dolor sit amet, <span style="color:red;">ea ignota verear</span> quaerendum
</div>
之后:
<div id="test" contenteditable="true">
Lorem ipsum dolor sit amet, ea ignota verear quaerendum
</div>
提前谢谢
答案 0 :(得分:3)
试试这个:
JS:
function testdemo() {
var div = document.getElementById('test');
div.innerHTML = div.textContent;
}
Jquery的:
function testdemo() {
$('#test').html($('#test').text());
}
答案 1 :(得分:1)
jQuery版本如下:
function testdemo() {
$("#test").html($("#test").text());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="testdemo();">RUN</button>
<div id="test" contenteditable="true">
</div>
答案 2 :(得分:0)
function testdemo() {
var div = document.getElementById('test');
div.innerHTML = div.textContent;
}
<button onclick="testdemo();">RUN</button>
<div id="test" contenteditable="true">
<b>Lorem ipsum</b> dolor sit amet, <span style="color:red;">ea ignota verear</span> quaerendum
</div>
答案 3 :(得分:0)
看看这是否有帮助。
function testdemo() {
$('#test').html($('#test').text()).text();
}