了解使用JavaScript进行textarea选择的情况 [英] Understanding what goes on with textarea selection with JavaScript

查看:136
本文介绍了了解使用JavaScript进行textarea选择的情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 textarea 中的浏览器内编辑器。我已经开始寻找有关处理 textarea 选择的一些信息,并找到这个jQuery插件,fieldSelection 做了一些简单的操作。

I am working on an in-browser editor within a textarea. I have started looking for some information on dealing with textarea selection and found this jQuery plugin, fieldSelection that does some simple manipulation.

然而,它并没有解释发生了什么。

However, it doesn't explain what's going on.

我想了解更多有关textarea选择的信息。 JavaScript,最好带有前DOM3和后DOM30场景的描述。

I want to understand more on textarea selection in JavaScript, preferably with a description of both pre-DOM3 and post-DOM30 scenarios.

推荐答案

从PPK开始范围介绍。 Mozilla开发人员连接有关于 W3C选择的信息。 Microsoft将其系统记录在MSDN上在此处的答案中可以找到更多技巧。

Start with PPK's introduction to ranges. Mozilla developer connection has info on W3C selections. Microsoft have their system documented on MSDN. Some more tricks can be found in the answers here.

除了不兼容的界面,你会很高兴地知道 textarea 节点还有一些奇怪的现象。 。如果我没记错,当你在IE中选择它们时,它们的行为就像任何其他节点一样,但在其他浏览器中,它们有一个独立的选择范围,通过 .selectionEnd 和<$公开c $ c> .selectionStart 节点上的属性。

In addition to incompatible interfaces you'll be happy to know that there is extra bizarreness going on with textarea nodes. If I remember correctly they behave as any other nodes when you select them in IE, but in other browsers they have an independent selection range which is exposed via the .selectionEnd and .selectionStart properties on the node.

此外,你应该看一下 .contentEdiable 作为一种实时编辑内容的方法。从Firefox3的发布开始,现在所有浏览器都支持此功能。

Additionally, you should really take a look at .contentEdiable as a means to edit things live. From the release of Firefox3, this is now supported by all browsers.

这篇关于了解使用JavaScript进行textarea选择的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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