-1
我發現一個JavaScript書這個例子想了解domReady.done,domReady.timer的意思嗎?
// 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
手段?
我們不能因爲它們沒有包含在您在此提供的代碼中。一起等待DOM的是一個簡單的'setInterval',當dom-functions可訪問時被清除,因此dom已準備就緒。 'domReady.timer'是相應時間間隔的ID,'domReady.done'是表示dom是否準備就緒的標誌。 – Christoph
它只是一個標誌,表明dom是否準備就緒。但它是一個定製的JavaScript功能。 – Apurv