将脚本附加到DOM问题

时间:2016-05-31 10:22:14

标签: javascript asynchronous

我正在测试Google酒店定价工具,当我在head标签之间直接粘贴脚本时它工作正常,将值附加到DOM(附加截图)。 enter image description here但是如果以编程方式创建脚本,则无法创建这些值。代码如下所示:

工作示例:

<head>
    <script type="text/javascript">
        var google_conversion_id = 1;
        var google_conversion_domain = "www.googletraveladservices.com/travel/clk";
    </script>
    <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"></script>
</head>

非工作示例:

<script type="text/javascript">
    var google_conversion_id = 1;
    var google_conversion_domain = "www.googletraveladservices.com/travel/clk";
    var s = document.createElement("script");
    s.type = "text/javascript";
    s.src = "//www.googleadservices.com/pagead/conversion.js";
    document.head.appendChild(s);
</script>

0 个答案:

没有答案