gpt4 book ai didi

jQuery 和 document.write

转载 作者:行者123 更新时间:2023-12-01 00:35:27 25 4
gpt4 key购买 nike

我有以下脚本:

<script type="text/javascript">
$(document).ready(function(){
document.write("<script type=\"text/javascript\" src=\"http://site.com/script.js\"><\/script>");
});
</script>

当我将其放入页面时,它会重定向到我不想要的脚本。

I want to echo this javascript file where I insert the code above, so it is loaded once the page has. Currently when I am using the script above, it is only displaying the contents of the javascript file, and not the whole page.

我希望它将它放入我放置此脚本的页面中。

我这样做是为了一旦页面加载,其调用的脚本基本上就加载到位,因为当前此脚本导致页面在加载时停滞。

谢谢。

最佳答案

尝试:

$(document).ready(function(){ 
$('body').append("<script type=\"text/javascript\" src=\"http://site.com/script.js\"><\/script>");
});

document.write 在文档加载之前调用时将添加到文档中,但之后它将替换现有内容。

关于jQuery 和 document.write,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8049229/

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