本文介紹了從 contentEditable div 中刪除格式的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時(shí)送ChatGPT賬號(hào)..
我有一個(gè) contentEditable Div,我想刪除任何格式,尤其是復(fù)制和粘貼文本.
I have a contentEditable Div and I want remove any formatting especially for copy and paste text.
推薦答案
你試過使用innerText嗎?
Have you tried using innerText?
添加:
如果您想從粘貼到可編輯 div 的內(nèi)容中去除標(biāo)記,請(qǐng)嘗試創(chuàng)建臨時(shí) div 的舊技巧 - 請(qǐng)參見下面的示例.
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>
這篇關(guān)于從 contentEditable div 中刪除格式的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!