简体   繁体   English

将不可编辑的文本添加到contentEditable div的每一行的末尾

[英]Adding Un-editable text to the end of each line of a contentEditable div

I have a contenteditable div, but I want to add a few characters of uneditable, unselectable text to the end of each line. 我有一个contenteditable div,但我想在每行末尾添加一些无法编辑,无法选择的文本字符。 I have mocked up an example bellow, which adds a note of whether all the words on the line were spelled correctly or not: 我模拟了一个波纹管示例,其中添加了有关行中所有单词是否正确拼写的注释:

在此处输入图片说明

My div is a pretty simple contenteditable div: 我的div是一个非常简单的contenteditable div:

<div contentEditable="true" designMode="on" id="edit" style="border: 1px dashed black; width: 700px; height: 400px"></div>

Any idea how to tackle this? 任何想法如何解决这个问题? Thanks 谢谢

Maybe you can use float:right to position your good/bad labels on the right, and have the content flow around them. 也许您可以使用float:right将您的好/不好标签放在右边,并使内容围绕它们流动。 The alignment wouldn't be exactly like your example, but it might be made to work. 对齐方式与您的示例并不完全相同,但是可以使其正常工作。

It might look something like this example at jsFiddle . 它可能看起来像jsFiddle中的此示例


Update 更新

Here's a different approach that might work, depending on your needs: see jsFiddle here . 根据您的需求,这是一种可能有效的不同方法: 请参见jsFiddle here

In this second approach, I've split each line into its own <div> , and followed each line's div with a <span contentEditable=false>(Good!) . I've floated everything to the left, with a 在第二种方法中,我将每行划分为自己的<div> ,并在每行的div后面加上<span contentEditable=false>(Good!) . I've floated everything to the left, with a . I've floated everything to the left, with a clear:left` on the divs, so that each div lands on its own line. . I've floated everything to the left, with a在div上. I've floated everything to the left, with a clear:left`,以便每个div都位于其自己的行上。 This does exactly what you want (at least, in webkit browsers) -- as long as you can split your lines up like that. 只要您可以像这样拆分行,它就可以满足您的要求(至少在Webkit浏览器中)。

you should be super imposing a div (z-index greater than content div) on top of the contentEditable div with text "Good!","Error" etc.. This way, the content would not be editable through the contentEditable div. 您应该在contentEditable div的顶部加上一个带有文本“ Good!”,“ Error”等的div(z索引大于content div)。这样,内容将无法通过contentEditable div进行编辑。

You should be able to calculate the position of the div based on the number of characters on a line and the line number. 您应该能够根据一行上的字符数和行号来计算div的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使ExtJS GridPanel的某些单元格不可编辑 - making certain cells of an ExtJS GridPanel un-editable 如何制作部分不可编辑的表格单元格? - How to make a partially un-editable table cell? 在 ContentEditable Div 中的每个新行上创建 Span - Create Span on Each New Line in ContentEditable Div 如何在 contenteditable 元素中粘贴多行文本,以便每行始终位于自己的 div 中? - How to paste multiline text in a contenteditable element so that each line is always in its own div? 通过jquery设置文本框内容前缀和后缀,使其不可编辑? - Set textbox content prefix and postfix via jquery and make it un-editable? 如何使部分不可编辑的表格单元格与内联 JavaScript 函数兼容? - How to make a partially un-editable table cell compatible with inline JavaScript functions? 可编辑内容的div中的突出显示的文本:获取突出显示的文本的开始和结束 - Highlighted text in a contenteditable div: Get the start and the end of the highlighted text 在div长度结尾处制作可编辑的div换行 - make editable div break line at end of div length 如何将光标放在具有contenteditable的div标签中文本的末尾 - How to place cursor at the end of text in div tag with contenteditable 在输入按下时,防止在contenteditable div中添加换行符 - Prevent adding line break tags in contenteditable div on enter press
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM