简体   繁体   English

如何使用contentEditable = true选择两个元素的文本?

[英]How to select text of the two elements with contentEditable = true?

I would like to ask, how can I select text of the two HTML elements, which property contentEditable is set to true. 我想问一下,如何选择两个HTML元素的文本,其contentEditable属性设置为true。 When I start to select text with mouse in one element, the selection ends within it's range. 当我开始用鼠标在一个元素中选择文本时,选择将在其范围内结束。 Never reach the second element. 永远不要到达第二个元素。

I tried to apply also "user-select" property, but without effect. 我尝试也应用“用户选择”属性,但没有效果。

here is snippet. 这是片段。

<body>
<div contentEditable = true style="position:absolute; left: 10px; top:10px; width:100px; height:200px; border: 3px solid #73AD21;">
Donec tempus, nisi a pharetra placerat, diam nisi aliquam elit, a consectetur magna enim sed ligula. 
</div>

<div contentEditable = true style="position:absolute; left: 130px; top:10px; width:100px; height:200px; border: 3px solid #73AD21;">
The oldest browsers support only one way of registering event handlers, the way invented by Netscape. 
</div>
</body>

thanx a lot 非常感谢

You can wrap these <div> s inside another <div> and make it contentEditable="true" instead of these two. 您可以将这些<div>包裹在另一个<div>并使其成为contentEditable="true"而不是这两个。

<body>
  <div contentEditable="true">
    <div style="position:absolute; left: 10px; top:10px; width:100px; height:200px; border: 3px solid #73AD21;">
Donec tempus, nisi a pharetra placerat, diam nisi aliquam elit, a consectetur magna enim sed ligula.</div>
    <div style="position:absolute; left: 130px; top:10px; width:100px; height:200px; border: 3px solid #73AD21;">
The oldest browsers support only one way of registering event handlers, the way invented by Netscape.</div>
  </div>
</body>

JS Bin here . JS Bin 在这里

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

相关问题 在contenteditable =“true”div中锁定元素 - Locking elements in contenteditable=“true” div 如何在contenteditable区域上选择替换的文本 - How to select the replaced text on the contenteditable area 如何选择contenteditable div中的所有文本? - How to select all text in contenteditable div? 关于contenteditable = true元素的文本建议 - Text suggestions on a contenteditable=true element 如何将大量文本发送到 contenteditable=&quot;true&quot; 元素中? - How do I send a large amount of text into a contenteditable="true" element? 在contenteditable = true时选择文本将以user-select = none样式复制节点的文本; - Selecting text while contenteditable=true will copy text of nodes with style user-select=none; 可编辑的true元素和可编辑的false元素旁边的插入符号行为 - Caret behavior inside contenteditable true and next to contenteditable false elements 不删除 div 中 contenteditable 设置为 true 的子元素 - Not Removing Child elements in a div with contenteditable set to true 如何在没有子节点的contenteditable div中选择文本范围? - How to select text range within a contenteditable div that has no child nodes? 如何在contenteditable元素的文本内重复选择给定的字符串 - How to select a given string repeatedly within the text of a contenteditable element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM