Javascript 在 textarea 中显示行号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8431670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 05:59:31  来源:igfitidea点击:

Display line number in textarea

javascriptjquerynumberstextarealine

提问by aki

I want to display the line number in a textarea like this is possible in jQuery:

我想在 jQuery 中像这样在 textarea 中显示行号:

enter image description here

在此处输入图片说明

I looked for answers on SO but I can't find what I want

我在 SO 上寻找答案,但找不到我想要的

Display current line and column number for a textarea

显示文本区域的当前行号和列号

Limit number of lines in textarea and Display line count using jQuery

使用jQuery限制textarea中的行数并显示行数

Also, the solution I tried from the JSFiddle provided from the comments show me the textarea like this:

另外,我从评论中提供的 JSFiddle 中尝试的解决方案向我展示了这样的文本区域:

enter image description here

在此处输入图片说明

which line 1234 is the first line and the second line is 5678

其中第 1234 行是第一行,第二行是 5678

回答by James Hill

Download the plugin found here: http://alan.blog-city.com/jquerylinedtextarea.htm

下载在此处找到的插件:http: //alan.blog-city.com/jquerylinedtextarea.htm

Usage:

用法:

$(function() {

  // Target all classed with ".lined"
  $(".lined").linedtextarea(
    {selectedLine: 1}
  );

  // Target a single one
  $("#mytextarea").linedtextarea();

});

Fully functional demo: http://files.aw20.net/jquery-linedtextarea/jquery-linedtextarea.html (web.archive)

全功能演示:http: //files.aw20.net/jquery-linedtextarea/jquery-linedtextarea.html (web.archive)