Jquery 想了解domReady.done和domReady.timer的含义吗?
我在一本JavaScript书中找到了这个例子Jquery 想了解domReady.done和domReady.timer的含义吗?,jquery,javascript,javascript-framework,unobtrusive-javascript,Jquery,Javascript,Javascript Framework,Unobtrusive Javascript,我在一本JavaScript书中找到了这个例子 // Checks to see if the DOM is ready for navigation function isDOMReady() { // If we already figured out that the page is ready, ignore if (domReady.done) return false; // Check to see if a number of functions and
// Checks to see if the DOM is ready for navigation
function isDOMReady() {
// If we already figured out that the page is ready, ignore
if (domReady.done) return false;
// Check to see if a number of functions and elements are
// able to be accessed
if (document && document.getElementsByTagName && document.getElementById && document.body) {
// If they're ready, we can stop checking
clearInterval(domReady.timer);
domReady.timer = null;
// Execute all the functions that were waiting
for (var i = 0; i < domReady.ready.length; i++)
domReady.ready[i]();
// Remember that we're now done
domReady.ready = null;
domReady.done = true;
}
}
// calling the domReady function
domReady(function () {
alert("The DOM is loaded!");
tag("h1")[0].style.border = "4px solid black";
});
想了解domReady.done、domReady.timer的含义吗?domReady.done是一个标志,它将在DOM就绪后立即设置为true。domReady.timer是以window.setInterval开始的间隔的引用/句柄,因此在DOM准备就绪后,可以立即使用window.clearInterval清除该间隔,因为不再需要进行检查。我们不能这样做,因为您提供的代码中没有包含这些间隔。总的来说,等待DOM是一个简单的setInterval,当DOM函数可访问时,它会被清除,因此DOM已准备就绪。domReady.timer是相应间隔的id,domReady.done是指示dom是否就绪的标志。它只是指示dom是否就绪的标志。但它是一个定制的javascript函数。