简体   繁体   中英

Creating Text Editor like Line Numbers using jQuery and CSS, HTML

i was just wondering if any such thing is possible/available or not

For each line in my HTML Page i want a Line Number to be displayed in extreme left of the page similar like many Programming editors.. Do u know any such plugin or design that fulfills this ?

Here's something rough that I cooked up for the sake of simplicity and you are welcome to expand on it:

http://jsfiddle.net/L4MEu/2/

HTML:

<div id="linenum"></div>
<div id="content">
    test<br/>
    one<br>
    two

</div>​

CSS:

#linenum
{
    width: 5%;
    background-color: blue;
    color: #FFF;
    position: absolute;
    top: 0px;
    bottom: 0px;            
}
#content
{
    position: relative;
    left: 7%;
}
body
{
    overflow-x: hidden;
}

JQuery:

$(document).ready(function(){
      var splitCondition = new RegExp("<br/?>");
      var lines = $("#content").html().split(splitCondition);

      for(var i = 1; i <= lines.length; i++)
      {
        $("#linenum").append("&nbsp;" + i + ".<br/>");
      }
​
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM