[英]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.