显示textarea的当前行和列号 [英] Display current line and column number for a textarea

查看:108
本文介绍了显示textarea的当前行和列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的网络应用程序中创建一个文件编辑界面,我有一个文件内容的textarea。

I'm making a file edit interface in my web-app, I have a textarea with file contents.

当textarea聚焦时,我想输出光标的位置,即行号和列:这很有用,因为错误消息通常会产生一个行号,例如。

When textarea is focused, I want to output the position of the cursor, i.e. line number and column: this is useful because error messages usually yield a line number, for example.

问题是:我怎么弄清楚textarea中光标的位置?
我正在使用原型库。也许已经有了一个解决方案?

The question is: how do I figure out the position of the cursor in textarea? I'm using prototype library. Maybe there's a solution already?

我对textarea的花哨工具栏并不感兴趣,这些工具栏是由那些高级小部件提供的。

I'm not really interested in fancy toolbars for the textarea, which are offered by those advanced widgets.

推荐答案

您可以查看这两个链接:

You may want to check out these 2 links:

http ://www.dedestruct.com/2008/03/22/howto-cross-browser-cursor-position-in-textareas/ [原始来源不再存在,修改后的链接点到最新版本的网络存档]

https://developer.mozilla.org/En/DOM:Selection

..一旦你有了选择(光标索引)在文本中),您可以按换行符分割文本,从而获取行号。您可以通过从行的开头确定索引来获取列

..once you have a selection (cursor index in text), you can split your text by newlines, thus getting line number. you can get column by determining index from beginning of a line

这篇关于显示textarea的当前行和列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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