line numbers using jquery
<div id="line_numbers"></div>
<textarea cols="65" rows="15" name="comments" id="comments"></textarea>
<textarea cols="65" rows="15" name="matches" id ="matches"></textarea>
开发者_开发技巧
there are many examples out there( Html adding line numbers to textarea ) but i just want to implement line numbers for a text area using jquery.Please let me know how to go about it.Any help would be really appreciated
I haven't looked into any plugins. However, here's a simple way for you to get started.
CSS:
#line_numbers {clear:both; float: left; text-align: right}
jQuery:
$("#comments").change(function() {
var comment_lines = $("#comments").val().split('\n');
$("#line_numbers").html('');
for(i = 0; i < comment_lines.length; i++) {
$("#line_numbers").html($("#line_numbers").html() + (i+1) + "<br/>");
}
});
I've never used it, but there's also the JQuery Lined TextArea plugin.
精彩评论