我应该如何包含另一个js文件中的js文件? [英] How should I include a js file from another js file?

查看:49
本文介绍了我应该如何包含另一个js文件中的js文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从另一个javascript文件添加对javascript文件的引用的最佳方法是什么?

What is the best way to add a reference to a javascript file from another javascript file?

假设我的网页中包含一个js文件.此javascript依赖于另一个文件.所以我想在我的js文件中引用依赖关系,而不是从html代码中引用.我的想法正确吗?

Suppose that I have a js file included in my webpage. This javascript has a dependency on another file. So I want to reference the dependency within my js file, and not from the html code. Is my thinking correct?

我知道我可以创建一个 script DOM元素,然后将其附加到页面上,但这对我来说很不好.

I know I can create a script DOM element and then append it to the page, but that smells bad for me.

您对此有任何建议吗?

推荐答案

创建 script DOM元素是唯一可用的方法.在检查了jQuery和YUI的源代码之后,我找不到更好的方法.两者都使用此技术.在jQuery中查看 globalEval函数和_

Creating a script DOM element is the only available way as far as I know. After checking the source code of jQuery and YUI, I couldn't find a better way. Both use this technique. Check out the globalEval function in jQuery, and the _scriptNode function in YUI.

这篇关于我应该如何包含另一个js文件中的js文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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