开发者

line numbers using jquery

开发者 https://www.devze.com 2023-01-15 18:15 出处:网络
<div id=\"line_numbers\"></div> <textarea cols=\"65\" rows=\"15\" name=\"comments\" id=\"comments\"></textarea>
  <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.

0

精彩评论

暂无评论...
验证码 换一张
取 消