window.onload与document.ready jQuery [英] window.onload vs document.ready jQuery

查看:168
本文介绍了window.onload与document.ready jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两列的网站.我想在使用jQuery时都具有相同的高度.

I have a site with two columns. I want to have equal height on both using jQuery.

我正在尝试获取徽标列的高度.我有:

I'm trying to get the logo column height. I had:

$(document).ready(function() {
    alert($('#logo').height());
});​

,但没有用.所以我将其更改为:

and it didn't work. So I changed it to:

window.onload = function(){
    alert($('#logo').height());
}

它正在工作.这是怎么回事?

And it's working. What is going on in here?

推荐答案

在处理好$(document)内的图像高度和宽度时,我遇到了同样的问题,我发现了一些更好的参考资料来解决它...我希望这可能帮助某人

I had a same problem in handling Image height and width inside $(document)ready and I found some better referenses to solve it... I hope this may help some one

$(document).ready()

加载HTML文档且DOM准备就绪时,即使尚未加载所有图形,也会触发文档就绪事件.如果要在窗口加载之前为某些元素挂起事件,则$(document).ready是正确的位置.

The document ready event fired when the HTML document is loaded and the DOM is ready, even if all the graphics haven’t loaded yet. If you want to hook up your events for certain elements before the window loads, then $(document).ready is the right place.

代码:

$(document).ready(function() {
    // document is loaded and DOM is ready
    alert("document is ready");
});

$(window).load()

在完全加载整个页面(包括所有框架,对象和图像)之后,窗口加载事件将在稍后触发.因此,与图像或其他页面内容有关的功能应放置在窗口或内容标签本身的加载事件中.

The window load event fired a bit later, when the complete page is fully loaded, including all frames, objects and images. Therefore functions which concern images or other page contents should be placed in the load event for the window or the content tag itself.

代码:

$(window).load(function() {
    // page is fully loaded, including all frames, objects and images
    alert("window is loaded");
});

这篇关于window.onload与document.ready jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆