gpt4 book ai didi

javascript - 在 dom 加载后包含外部脚本

转载 作者:行者123 更新时间:2023-11-29 22:13:25 26 4
gpt4 key购买 nike

我有这个包含广告的脚本,现在我试图在 dom 加载后包含它。

<script type='text/javascript' src='http://ads.yashi.com/xxxx'></script>

以下内容对我不起作用

<script type='text/javascript'>
$( document ).ready(function() {
$.getScript("http://ads.yashi.com/xxxx");
});
</script>

最佳答案

你试过吗:

window.onload = function(){
$.getScript("http://ads.yashi.com/xxxx");
};

您是否还检查了“网络”选项卡(Firebug 或 Chrome 开发工具),看看它是否尝试加载脚本并成功?

另外,如果你想在脚本加载后做一些事情,你需要包含一个回调函数:

$.getScript(url, function(data, textStatus, jqxhr) {
// do something now
});

关于javascript - 在 dom 加载后包含外部脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16800800/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com