我在FireFox浏览器中获取Jquery is not defined,但在opera中工作,这里是ex http://eef.percipio.me/index/charts。
我用以下命令加载jquery
if (!window.jQuery) {
var jq = document.createElement('script'); jq.type = 'text/javascript';
// Path to jquery.js file, eg. Google hosted version
jq.src = 'http://eef.percipio.me/themes/third_party/charts/js/jquery-1.10.2.min.js';
document.getElementsByTagName('head')[0].appendChild(jq);
}这段代码似乎有问题,因为如果我这样做了,它就可以工作了
<script src="http://eef.percipio.me/themes/third_party/charts/js/jquery-1.10.2.min.js" type="text/javascript">发布于 2014-01-08 21:56:51
你的链接对我来说是断断续续的,甚至在打开firebug的时候也是如此。对我来说,这看起来像是时间问题,我认为在尝试使用它之前,你需要确保jQuery已经加载。
试着用谷歌搜索“load jquery if not load”或者看看this article --它提供的代码应该会对你有所帮助。
此外,here也是关于类似问题的另一个问题。
发布于 2014-01-08 22:10:37
对我来说也是断断续续的。这绝对是个时机问题。
您可以轮询jQuery的可用性:
function withjQuery ($) {
// use $
}
function pollForjQuery () {
if (window.jQuery) {
withjQuery(window.jQuery);
} else {
// checks for jQuery again in 50ms
setTimeout(pollForjQuery, 50);
}
}
// check for jQuery in 0, 50, 100, 150, 200ms etc.
pollForjQuery();https://stackoverflow.com/questions/20997376
复制相似问题