把重点放在div contenteditable元素上 [英] Set focus on div contenteditable element

查看:182
本文介绍了把重点放在div contenteditable元素上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个< div contenteditable = true> 其中我通过所见即所得定义了一些元素。例如< p> < h1> 等。我想直接把焦点放在一个这个元素。

例如在< p id =p_test> 。但似乎 focus()函数在< div> 元素, >< p> 元素...



是否有另一种方法来定义焦点?我注意到,jQuery焦点()没有为宽度和高度为0的contenteditable DIV工作。我用.get(0)替换它。焦点() - 本地JavaScript焦点方法 - 它的工作。


I have a <div contenteditable=true> where I define by a WYSIWYG some elements. For example <p>,<h1>, etc. I would like to put directly the focus on one of this elements.

For example on <p id="p_test">. But it seems that focus() function doesn't work on <div> elements, <p> elements...

Is there a another means to define the focus in my case?

解决方案

I noticed that jQuery focus() did not work for my contenteditable DIV with width and height of 0. I replaced it with .get(0).focus() - the native javascript focus method - and it works.

这篇关于把重点放在div contenteditable元素上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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