如何在关闭body标签后创建元素 [英] How do I create an element after the closing body tag

查看:95
本文介绍了如何在关闭body标签后创建元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查文档中是否包含jQuery。如果不是,我希望在关闭body标签后创建一个元素。

I am checking if jQuery is included in the document. If not I want create an element after the closing body tag.

<script type="text/javascript">
if( !(typeof jQuery === 'function') ){
    var script = document.createElement('script');
    script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js';
    script.type = 'text/javascript';
    var head = document.getElementsByTagName("head")[0];
    head.appendChild(script);
}
</script>

如果我使用body标签进行此操作,它会将其追加到顶部。我想要将它追加到body标签的末尾,或者在关闭它之后立即添加。

If I do this with the body tag it appends it to the top. I wanna either append it to the end of the body tag or right after closing it.

请帮助。

推荐答案

使用 document.body.appendChild()。它会在body标签的末尾添加元素。

Use document.body.appendChild(). It will append the element at the end of the body tag.

顺便说一句,jAndy是对的,几乎没有必要在body的最后动态添加一个javascript文件。

By the way, jAndy is right, there is little need to add a javascript file dynamically at the end of the body.

这篇关于如何在关闭body标签后创建元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆