我有一个令人满意的div,我需要在插入位置插入文本,
这可以在IE中轻松完成 document.selection.createRange().text = "banana"
有没有类似的方法在Firefox/Chrome中实现这一点?
(我知道这里存在一个解决方案,但它不能在contenteditable div中使用,看起来很笨拙)
谢谢!
我想阻止用户在contenteditablediv中粘贴不允许的标记.
我想将粘贴限制为粗体,斜体,打击,下划线和链接.
什么是最好的方式(我正在使用jQuery)?
这不是JQuery Text Editor Paste Without Formatting的重复.我不想在没有格式化的情况下粘贴.我想选择/限制一些标记.
我已经阅读了以下问题,没有提供明确答案:
我有一个contenteditableDIV 元素,我不想粘贴 CSS,基本上只是它只粘贴到innerText,而不是innerHTML。我没有使用任何库,只是纯粹的 Javascript。目前,如果我从网站复制一些 CSS 文本,然后将其粘贴到我的 div 元素中,样式也会随之而来。我想要它,这样如果我要粘贴它,CSS 就不会出现,或者使 CSS 被oninput我为 div 元素的类放置的事件中的字体/颜色覆盖。那么,我该怎么做呢?
DIV 元素的 CSS:
.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;
}
Run Code Online (Sandbox Code Playgroud)
HTML 片段:
<div class="mystyle" contenteditable="true" id="input"
oninput='//what to put here?'></div>
Run Code Online (Sandbox Code Playgroud)