简体   繁体   English

如何 select Contenteditibale div 中的所有文本?

[英]How to select all text inside Contenteditibale div?

I'm trying to create multiple Contenteditibale div with text inside, so when i want to select the whole text (in all the div's) using either the mouse or ctrl + a, using only vanilla js.我正在尝试使用鼠标或 ctrl + a 创建多个 Contenteditibale div,其中包含文本,所以当我想 select 整个文本(在所有 div 中)时,只使用 vanilla js。

 body { font-size:16px; }.wrapper { display: flex; justify-content: center; align-items: center; flex-direction:column; width: 100vw; height:100% }.contenteditable { width:400px; height:200px; border:4px dashed red; }.contenteditable:focus { outline: red 2px solid; }
 <div class=wrapper> <div class="contenteditable" contenteditable="true"></div> <div class="contenteditable" contenteditable="true"></div> <div class="contenteditable" contenteditable="true"></div> <div class="contenteditable" contenteditable="true"></div> <div class="contenteditable" contenteditable="true"></div> </div>

You can use textContent;您可以使用文本内容;

var node = document.getElementsByClassName('wrapper')[0];
var text = node.textContent;// get's all the text inside the wrapper element

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM