开发者

Javascript creating a new line on the html page?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜