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
Display line number in textarea
提问by aki
I want to display the line number in a textarea like this is possible in jQuery:
我想在 jQuery 中像这样在 textarea 中显示行号:
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
Also, the solution I tried from the JSFiddle provided from the comments show me the textarea like this:
另外,我从评论中提供的 JSFiddle 中尝试的解决方案向我展示了这样的文本区域:
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)