d3.js和document.onReady [英] d3.js and document.onReady
问题描述
我刚开始使用 d3.js ,有一个细节完全没有我:我如何让我的代码执行只有在DOM准备好接收输入?
我可以,当然,使用像jQuery,但似乎过多。 / p>
在每个d3.js示例我遇到似乎没有特殊的 document.onReady()
类型的例程,但所有的例子工作完美无瑕。但是,在我的测试代码,但是,代码完全失败,如果在DOM准备好之前执行(抛出我的代码到 window.onload
确认这一点)。
这是什么?
在任何被使用的html元素之下,以便在开始执行javascript之前加载dom的一部分。
只需将javascript放在body的底部即可通常足够好。
I'm just getting started with d3.js and there is one detail which is completely eluding me: how do I have my code execute only after the DOM is ready to receive input?
I could, of course, use something like jQuery but that seems excessive.
In every d3.js example I've encountered there seems to be no special document.onReady()
type of routine, yet all the examples work flawlessly. When testing code on my end, however, the code totally fails if executed before the DOM is ready (throwing my code into a window.onload
confirms this).
What gives?
You'll notice in their examples that their javascript is below any of the html elements that is utilized so that part of the dom is loaded before it starts executing the javascript.
Simply putting your javascript at the bottom of the body is usually good enough.
这篇关于d3.js和document.onReady的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!