jQuery document.ready与pageLoad [英] jQuery document.ready vs pageLoad

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

问题描述

我从另一个开发人员那里接过了一个现有项目,我在代码中注意到我在三个不同的事件处理程序中执行js代码...

I've picked up an existing project from another developer and ive noticed in the code that they are executing js code within three different event handlers...

function pageLoad() {
//execute code
}

$(document).ready(function() {
//execute code
});

$(function() {
//execute code
});

我的问题是-他们都完全一样吗?或至少是最后两个?我知道pageLoad是由.NET框架调用的,因此它不依赖于已加载的jQuery库,就像后两者一样-这还是我的理解-有关吗?

My question is - arent they all exactly the same? Or at least the last two? I understand that pageLoad is called by the .NET framework so it's not dependent on the jQuery library having loaded like the second two are - that's my understanding anyway - is that about correct?

推荐答案

$(document).ready()

  • 理想的一次初始化.

  • Ideal for one time initialization.

优化黑魔法;可能比pageLoad()稍早运行.

Optimization black magic; may run slightly earlier than pageLoad().

不将功能重新附加到受部分回发影响的元素上.

Does not re-attach functionality to elements affected by partial postbacks.

pageLoad()

  • 如果与UpdatePanels一起使用,则不适合一次初始化.

  • Unsuitable for one time initialization if used with UpdatePanels.

在某些浏览器中优化程度略低,但保持一致.

Slightly less optimized in some browsers, but consistent.

完美地将功能重新附加到UpdatePanels中的元素.

Perfect for re-attaching functionality to elements within UpdatePanels.

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

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