当焦点位于其他元素上时,保持在可编辑的DIV上进行选择 [英] Keep selection made on editable DIV when focus is on other element

查看:146
本文介绍了当焦点位于其他元素上时,保持在可编辑的DIV上进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有这个问题很长一段时间,我只是不知道如何解决它。我想创建一个简单的WYSYWYG编辑器,我有一些问题。

目前我有这个:

 < div id =editorcontenteditable =true>< / div> 
< input type =buttonvalue =B
onmousedown =document.execCommand('bold',false,null); return false;/>所以,如果我的DIV里面有一些文字,选择它并点击B它就是我的DIV文件转换为BOLD,并保持选中,但这不适用于Opera和IE。





我不知道如何让可编辑的DIV不仅能保持焦点,而且还能保存文本选择。任何想法?

解决方案




I have had this problem for a long time and I just can't figure out how to fix it. I want to create a simple WYSYWYG editor and I have some problems.

Currently I have this:

<div id="editor" contenteditable="true"></div>
<input type="button" value="B" 
       onmousedown="document.execCommand('bold',false,null); return false;"/>

So, if I have some text inside my DIV, select it and click on "B" it is converted to BOLD, and remains selected, but this doesn't work on Opera and IE.

I just don't know how to make the editable DIV not only keep the focus but also the text selection.

Any idea?

解决方案

Two possible options are:

这篇关于当焦点位于其他元素上时,保持在可编辑的DIV上进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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