在焦点/单击时选择contenteditable div中的所有文本 [英] select all text in contenteditable div when it focus/click

查看:134
本文介绍了在焦点/单击时选择contenteditable div中的所有文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的contenteditable div如下所示。

I've got contenteditable div as below.

<div style=" border:solid 1px #D31444" contenteditable="true">12 some text...</div>

我需要的是,当我点击div时,所有文本都会自动被选中。你可以给我解决方案吗?

What I need is, when I click on the div, all the text will automatically get selected. Can you give me solution please?

推荐答案

试试这个:

<div style="border:solid 1px #D31444"
     contenteditable="true"
     onclick="document.execCommand('selectAll',false,null)">12 some text...</div>

这篇关于在焦点/单击时选择contenteditable div中的所有文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆