从contentEditable div中删除格式 [英] Remove formatting from a contentEditable div
本文介绍了从contentEditable div中删除格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个contentEditable Div,我想删除任何格式,尤其是复制和粘贴文本。 解决方案
innerText?
添加:
如果要从粘贴到可编辑div的内容中去除标记,创建一个临时div的老破解 - 见下面的例子。
<!DOCTYPE html>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> Strip可编辑div标记< / title>
< script type =text / javascript>
函数strip(html){
var tempDiv = document.createElement(DIV);
tempDiv.innerHTML = html;
return tempDiv.innerText;
}
< / script>
< / head>
< body>
< div id =editableDivcontentEditable =true>< / div>
< / body>
< / html>
I have a contentEditable Div and I want remove any formatting especially for copy and paste text.
解决方案
Have you tried using innerText?
ADDED:
If you want to strip markup from content pasted into the editable div, try the old hack of creating a temporary div -- see example below.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Strip editable div markup</title>
<script type="text/javascript">
function strip(html) {
var tempDiv = document.createElement("DIV");
tempDiv.innerHTML = html;
return tempDiv.innerText;
}
</script>
</head>
<body>
<div id="editableDiv" contentEditable="true"></div>
<input type="button" value="press" onclick="alert(strip(document.getElementById('editableDiv').innerText));" />
</body>
</html>
这篇关于从contentEditable div中删除格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文