[英]How to prevent CSS from being pasted in a contenteditable div
I have a contenteditable
DIV element, and I don't want to have CSS pasted, basically only it only pastes into innerText
, but not innerHTML
.我有一个
contenteditable
DIV 元素,我不想粘贴 CSS ,基本上只是它只粘贴到innerText
,而不是innerHTML
。 I'm not using any library, just pure Javascript.我没有使用任何库,只是纯粹的 Javascript。 Currently, if I were to copy some CSS text from a site, and then paste it into my div element, the style comes with it as well.
目前,如果我要从站点复制一些 CSS 文本,然后将其粘贴到我的 div 元素中,样式也会随之而来。 I want it so if I were to paste it, the CSS wouldn't come, or make it so the CSS gets overriden by the font / color from a
oninput
event, that I put for the div element's class.我想要它,所以如果我要粘贴它,CSS 就不会出现,或者让它这样 CSS 被来自
oninput
事件的字体/颜色覆盖,我为 div 元素的 ZA2F2ED4F8EBC2CAB1DDC44 放置。 So, how would I do this?那么,我该怎么做呢?
CSS for DIV element: CSS 用于 DIV 元素:
.mystyle {
border:4px solid gray;
background-color: #00000070;
color: white;
font-family: 'Courier New', Courier, monospace;
width: 1245px;
height: 200px;
padding: 10px;
font-size: 14px;
text-shadow: 3px 3px #3f3f3f;
text-align: justify;
}
HTML Snippet: HTML 代码段:
<div class="mystyle" contenteditable="true" id="input"
oninput='//what to put here?'></div>
try this: contenteditable="plaintext-only"
.试试这个:
contenteditable="plaintext-only"
。
doesn't work for all browsers, but does for Chrome - the only browser that matters... :)不适用于所有浏览器,但适用于 Chrome - 唯一重要的浏览器... :)
found at: contenteditable - HTML: Hypertext Markup Language |发现于: contenteditable - HTML:超文本标记语言 | MDN at section "Browser compatibility".
MDN在“浏览器兼容性”部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.