javascript noob… document write

前端 未结 5 1940
既然无缘
既然无缘 2021-01-22 10:55

I\'m trying to use Javascript to load more links in my nav bar.

This is what I tried; I just wanted one link in my nav to load more beneath it.



        
5条回答
  •  滥情空心
    2021-01-22 11:41

    document.write should really only be used while the document is loading. Calling it after the document is loaded will clear the current document and write some new content. To add new content to the page, you would need to create new DOM objects and add them to the page or modify existing DOM objects.

    Here's a small example of modifying the page you can see in action here: http://jsfiddle.net/jfriend00/zVS39/

    HTML:

    collections
    
    

    Javascript:

    function show() {
        var o = document.getElementById("moreText");
        o.innerHTML = "
    collection 1
    collection 2
    etc...
    "; }

提交回复
热议问题