Динамично номериране на редовете в текстареа

lam3r4370

Registered
Някой може ли да ми каже как да го направя? Само идеята.С JavaScript.Т.е номериране on the go?
 
Така устроива ли те.
Код:
<html><head>
<title>Banana</title>
<script>
function countLines()
{
  var area = document.getElementById("texta")
		
  var text = area.value.replace(/\s+$/g,"")

  var split = text.split("\n");
  var temptext = [];
  
  
  
  for (var i = 0; i < split.length; i++ ){
	temptext = temptext + ((i+1)+'. '+split[i]) + '\n';
	console.log(temptext);
  }
  area.value = temptext;
}
</script>
</head>
<body>
<textarea id="texta" cols="30" rows="8">
I think you could use the split function to break
the text into an array.
Then check the array's length to get
the line count.
</textarea>
<br>
<button onclick="countLines()">count</button>
</body></html>
 
hpstuff каза:
Така устроива ли те.
Код:
<html><head>
<title>Banana</title>
<script>
function countLines()
{
  var area = document.getElementById("texta")
		
  var text = area.value.replace(/\s+$/g,"")

  var split = text.split("\n");
  var temptext = [];
  
  
  
  for (var i = 0; i < split.length; i++ ){
	temptext = temptext + ((i+1)+'. '+split[i]) + '\n';
	console.log(temptext);
  }
  area.value = temptext;
}
</script>
</head>
<body>
<textarea id="texta" cols="30" rows="8">
I think you could use the split function to break
the text into an array.
Then check the array's length to get
the line count.
</textarea>
<br>
<button onclick="countLines()">count</button>
</body></html>
Не.
Искам докато цъкам ентер ,например ,да добавя нов ред.Ако намерите кода от Bespin (https://bespin.mozillalabs.com/)(,аз не успях ,голяма е бъркотия) ,ще е супер!
 
Ти поглеждал ли си го изобщо там не се прави с никаква textarea а сичко се рисува с canvas.
 
hpstuff каза:
Ти поглеждал ли си го изобщо там не се прави с никаква textarea а сичко се рисува с canvas.
Е ,добре ,с канвас ,не ми пречи.
 

Back
Горе