<script> document.ready = function(callback) { //兼容FF,Google if(document.addEventListener) { document.addEventListener('DOMContentLoaded', function() { document.removeEventListener('DOMContentLoaded', arguments.callee, false); callback(); }, false) } //兼容IE else if(document.attachEvent) { document.attachEvent('onreadystatechange', function() { if(document.readyState == "complete") { document.detachEvent("onreadystatechange", arguments.callee); callback(); } }) } else if(document.lastChild == document.body) { callback(); } } document.ready(function() { if(条件) {要执行的内容} }); </script>
转载于:https://my.oschina.net/u/3112661/blog/1595526