문제

okay I have an a script running that process a lot of data basically I am using the line below

 document.getElementById("message").innerHTML = JSON.stringify(stringbuild.hello);

problem is every time this line is send to message textbox it just overwrites the previous line from a previous output .

how can I make each output emit to a new empty line and keep any other previous data in the textbox

도움이 되었습니까?

해결책 2

In a <textbox> use \n which is a newline character:

node = document.getElementById("message");
node.innerHTML += JSON.stringify(stringbuild.hello) + '\n';

Don't use <br /> in a <textbox>.

And add it always at the end of the line, or you'll have the first line being empty.

다른 팁

If the 'message' element is a regular HTML element (e.g. a <div>), try would work:

document.getElementById("message").innerHTML += "<br>" + JSON.stringify(stringbuild.hello);
  • The += is an 'augmented' assignment operator which appends the current string with whatever value is provided to the right.
  • The <br> is an html line break character, used to make place the the new string directly underneath the previous string.

For an input element <input type="text"> or <textarea>, use this:

document.getElementById("message").value += "\n" + JSON.stringify(stringbuild.hello);
  • The value property is used to access the current value of the input element, and should be used instead of innerHTML.
  • The \n is the escape sequence for a new line character.

Demonstration

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top