I have a javascript function that prints some textboxes when the user clicks a button.
Howeve开发者_JS百科r when the user clicks the buttons multiple times the textboxes just go along the page but I want it to always be on a new line every time the function is called.
I tried this
x=document.write ('<br/>');
document.getElementById('txtara').appendChild(x)
But that just clears my page to blank white.
Thanks
document.getElementById ('txtara').innerHTML += '<br>';
You did that wrong. document.write
writes to the end of the page, and doesn't return an HTML element. What you need is this:
var x = document.createElement('br');
document.getElementById('txtara').appendChild(x)
Using document.write will clear everything else from the page. You should use CSS to style your text boxes so they appear as you want them to.
精彩评论