在TextArea的specefic行上附加文本

时间:2018-04-27 13:30:16

标签: javascript



var myRouter = require('./myRouter')

app.use('/folder', myRouter)




使用此代码,我可以在第8行添加值,但问题是我的文本将是这样的:

let someText = "Hi THIS IS MY TEXT AND I WANT IT CENTRED NOT ON THE TOP OF THE TEXTAREA"; //This would be replaced with your textarea value
let stringSplit = someText.split("\n");

if (stringSplit.length < 8) {
  //Add enough items to be 8 rows
  for (let x = stringSplit.length; x < 8; x++) {
    stringSplit.push("");
  }
}

//replace the 8th row value with your name
stringSplit[7] = "YourName";

//Join the array back into a string separated by newline between each element value
someText = stringSplit.join("\n");
//Set your textarea value = someText
console.log(someText);

而不是

    EXEMPLE OF TEXT






       VALUE(8throw)

我想让我的文本居中,并且值要在第8行,而不是让我的文本放在textarea的顶部,而是我的值在底部。 我想用我的文字替换3个细分线来制作这样的东西。

            /n
            /n
            /n
        MY TEXT


       Value(8th row)

我想要实现的是this

2 个答案:

答案 0 :(得分:1)

交替添加到数组的开头和结尾:

&#13;
&#13;
<div className="btn-wrap">
    <Button value = '1'>1</Button>
    <Button value = '2'>2</Button>
    <Button value = '3'>3</Button>
    <Button value = '+' onClick={e => console.log('+ clicked')}>3</Button>
    <Button value = '-' onClick={e => console.log('- clicked')}>3</Button>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

let string = "Example text";
let stringSplit = string.split("\n");
for (let x = stringSplit.length; x < 7; x++) {
  if (x % 2 == 0) {
    stringSplit.unshift("");
  } else {
    stringSplit.push("");
  }
}
stringSplit[7] = "Last line";
console.log(stringSplit.join("\n"));