在文本区域中获取行号

编程入门 行业动态 更新时间:2024-10-28 08:22:44
本文介绍了在文本区域中获取行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: 找出行"(行)文本区域中的光标编号

我想在HTML textarea 元素中找到用户光标所在的行号.

I want to find out the line number that a user's cursor in on in a HTML textarea element.

使用javascript和jquery是否可能?

Is this possible using javascript and jquery?

推荐答案

通过单击按钮即可使用.从中被盗文本区域中光标的(行)数

This works with button click. Stolen from Find out the 'line' (row) number of the cursor in a textarea

​function getline() { var t = $("#t")[0]; alert(t.value.substr(0, t.selectionStart).split("\n").length); }​

HTML

​<textarea rows="6" id="t"> there is no love in the ghetto so come here and get it </textarea> <input type="button" onclick="getline()" value="get line" />​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

更多推荐

在文本区域中获取行号

本文发布于:2023-11-10 00:27:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573852.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行号   文本   区域

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!