我在一个aspx页面中使用fancybox。document ready函数在该页面中无法为灯箱工作。有人告诉我要编写新的javascript代码来加载该页面上的灯箱。
我在一个aspx页面中使用fancybox。document ready函数在该页面中无法为灯箱工作。有人告诉我要编写新的javascript代码来加载该页面上的灯箱。
在DOM准备就绪时执行操作。
$(function(){
// DOM Ready - do your stuff
});
试试这个:
document.addEventListener('DOMContentLoaded', function() {
// ...
});
适用于现代浏览器和IE9以上版本
window.onload = function() {};
defer
是最好的解决方案。例如,<script src="demo_defer.js" defer></script>
More information at W3 Schools.
jQuery.noConflict();
(function($) {
$(function() {
// by passing the $ you can code using the $ alias for jQuery
alert('Page: ' + $('title').html() + ' dom loaded!');
});
})(jQuery);
$(window).load(function(){ // ...})
。 - Ram$(document).ready(function(){ ... })
几乎相同。load()
将等待图形加载完成。 - alexbusu