41. 无阻塞脚本与 DOM 在脚本加载完成的时候, DOM 可能 DOM 还没有 DOMContentLoaded( 加载速度快或者来自 cache) 访问 DOM 是危险的 DOM 可能已经 DOMContentLoaded 了 绑定 DOMContentLoaded 事件永远也不会被触发 如何判断 DOM 是否 ready DOM 甚至已经 Onload 了 (IE) 05/09/11
42. 如何解决以上问题? DOM 还没有 DOMContentLoaded( 加载速度快或者来自 cache) 保证 DOM 操作注册在 DOMContentLoaded 事件中 DOM 可能已经 DOMContentLoaded 了 绑定 DOMContentLoaded 事件永远也不会被触发 通过 document.readyState == “complete” 判断 DOMready DOM 甚至已经 Onload 了 (IE) document.readyState 依然有效 05/09/11
51. 被各种 ajax 库宠坏的孩子们 看看最原始的 Ajax 吧 var httpRequest; if (window.XMLHttpRequest) { // Mozilla, Safari, ... httpRequest = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } httpRequest.onreadystatechange = function(){ if (httpRequest.readyState === 4) { if (httpRequest.status === 200) { // perfect! } else { // there was a problem with the request, // for example the response may be a 404 (Not Found) // or 500 (Internal Server Error) response codes } } else { // still not ready } }; httpRequest.open('GET', ‘http://url', true); httpRequest.send(null); 05/09/11