获取文本区域中的行号

Fre*_*cer 23 html javascript jquery textarea

可能重复:
找出textarea中光标的"行"(行)编号

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

这可能使用javascript和jquery吗?

cod*_*biz 20

这适用于按钮单击.被盗从查找textarea中光标的"行"(行)编号

?function getline()
{
    var t = $("#t")[0];
    alert(t.value.substr(0, t.selectionStart).split("\n").length);
}?
Run Code Online (Sandbox Code Playgroud)

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" />??????????????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)

  • 这不包括自动换行引起的换行. (4认同)
  • @RobW:我认为OP不需要 (4认同)

归档时间:

查看次数:

14848 次

最近记录:

13 年,2 月 前