开发者

Javascript creating a new line on the html page?

开发者 https://www.devze.com 2023-03-17 00:31 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消