Append [removed] Tag to Body?

后端 未结 2 1855
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 18:43

I want to append a script tag to the body of my HTML page. I added the following in my page:



        
2条回答
  •  萌比男神i
    2020-12-19 19:02

    The error you are getting is because there is no initialize() function. If you declare one there will be no error.

    function loadScript() {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
        document.body.appendChild(script);
        console.log('loadScript');
    }
    
    function initialize() {
        console.log('initialize');
    }
    
    window.onload = loadScript;
    

提交回复
热议问题