C# 文本区域内的有序列表(行号)

C# 文本区域内的有序列表(行号),c#,javascript,jquery,html,ajax,C#,Javascript,Jquery,Html,Ajax,我需要实现文本区域与有序列表文本。我已经这样做了,但行号必须在按下回车键后才能增加。 以下是我的努力: 代码 var lineObjOffsetTop=2; createTextAreaWithLines('codeTextarea'); 函数createTextAreaWithLines(id) { var el=document.createElement('DIV'); var ta=document.getElementById(id); ta.parentNode.insertBefo

我需要实现文本区域与有序列表文本。我已经这样做了,但行号必须在按下回车键后才能增加。

以下是我的努力:

代码

var lineObjOffsetTop=2;
createTextAreaWithLines('codeTextarea');
函数createTextAreaWithLines(id)
{
var el=document.createElement('DIV');
var ta=document.getElementById(id);
ta.parentNode.insertBefore(el,ta);
el.appendChild(ta);
el.className='textAreaWithLines';
el.style.width=(ta.offsetWidth+30)+“px”;
ta.style.position='绝对';
ta.style.left='30px';
el.style.height=(ta.offsetHeight+2)+“px”;
el.style.overflow='hidden';
el.style.position='相对';
el.style.width=(ta.offsetWidth+30)+“px”;
var lineObj=document.createElement('DIV');
lineObj.style.position='绝对';
lineObj.style.top=lineObjOffsetTop+'px';
lineObj.style.left='0px';
lineObj.style.width='27px';
el.insertBefore(lineObj,ta);
lineObj.style.textAlign='右';
lineObj.className='lineObj';
var字符串=“”;
对于(变量no=1;no0)string=string+'
'; 字符串=字符串+否; } ta.onkeydown=function(){positionLineObj(lineObj,ta);}; ta.onmousedown=function(){positionLineObj(lineObj,ta);}; ta.onscroll=function(){positionLineObj(lineObj,ta);}; ta.onblur=function(){positionLineObj(lineObj,ta);}; ta.onfocus=function(){positionLineObj(lineObj,ta);}; ta.onmouseover=function(){positionLineObj(lineObj,ta);}; lineObj.innerHTML=字符串; } 功能位置线obj(obj,ta) { obj.style.top=(ta.scrollTop*-1+lineObjOffsetTop)+'px'; }
您可能希望使用contenteditable标记,而不是使用这样的文本区域

下面是一个可能的例子

HTML:


JQuery:

var yourContent = "<ol><li>Go to home.</li><li>I need to installl window 8 and sql server 2012 by tommorow so that i can work with my project well and Need to clarify.</li><li>Test application.</li></ol>";

$('.orderedList').html(yourContent);
var yourContent=“
  • 回家。
  • 我需要在tommorow之前安装L window 8和sql server 2012,以便我能够很好地处理我的项目,并需要澄清。
  • 测试应用程序。
  • ”; $('.orderedList').html(yourContent);
    然后,您可以使用一些JQuery技巧将其与表单一起提交


    希望这有帮助

    也许不要重新发明轮子,使用像YUI这样强大的工具:我已经编辑了我的问题。请考虑重新开放。我已经做了一个RND,并再次发布了需要,谢谢,但我需要在键入文本在TeTaTeRa和当按下输入,新的行号应该自动添加。我已经试过了,但我做不到巴拉圭式的。
    <div class="orderedList" contenteditable="true">
    </div>
    
    var yourContent = "<ol><li>Go to home.</li><li>I need to installl window 8 and sql server 2012 by tommorow so that i can work with my project well and Need to clarify.</li><li>Test application.</li></ol>";
    
    $('.orderedList').html(yourContent);